I style my UITabBarItem titles globally as follows:
UITabBarItem.appearance().setTitleTextAttributes(TextStyle.tabTitle(colored: false).attributes, for: .normal)
UITabBarItem.appearance().setTitleTextAttributes(TextStyle.tabTitle(colored: true).attributes, for: .selected)
In iOS 15, I need to override the new behaviour where the tab bar background is hidden at the scroll edges. I can do that like this:
let appearance = UITabBarAppearance()
appearance.configureWithDefaultBackground()
tabBar.standardAppearance = appearance
tabBar.scrollEdgeAppearance = appearance
However, this seems to override the font of the tab bar item titles, and reset them back to the default. I can't seem to override the tab bar hiding behaviour, and retain my custom font.
You can use
let tabBarItemAppearance = UITabBarItemAppearance()
tabBarItemAppearance.normal.titleTextAttributes = [TextStyle.tabTitle(colored: false).attributes]
tabBarItemAppearance.selected.titleTextAttributes = [TextStyle.tabTitle(colored: false).attributes]
Related
I'm trying to change the navigationbar color dynamically. But the problem is that unless I scroll to the top only the the new color is visible otherwise the old color is seen. I'm using the below code to set the color. My requirement is that if I change the color I want the navigation bar to show the new color irrespective of the scrolling. I would really appreciate your suggestions.
let navigationBarAppearance = UINavigationBarAppearance()
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
navigationBarAppearance.backgroundColor = .purple
I've tried the code thats been specifically given for iOS 15 and later
In Xcode I have this app that uses tabBarItem. There are 5 items and occasionally when I'm on a specific page I get this weird overlay of the tabBarItems (see pictures). I say occasionally, because it does not do it always but it is still very frequent. Not sure if it is just a limitation with tabBarItem or if I have a bug.
This is how it SHOULD look:
This is how it SHOULD NOT look, but does:
As you can see in the second image the tabBar is being overlayed onto the other text rather than disappearing behind it. It's odd that it behaves differently for each tab.
I can fix the issue with
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .black
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
But need a fix that would work for IOS 11+
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().backgroundColor = .black
Setting the appearance of a UINavigationBar title, background, etc. based on whether it is showing large or normal is no problem. But how to update the appearance / tint color of the bar button items accordingly?
Have a code at the following appearance and the code that I used to create it:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [MyCiewController.self]).tintColor = .orange
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .orange.withAlphaComponent(0.5)
appearance.backgroundEffect = UIBlurEffect(style: .systemChromeMaterialDark)
// Set different title colors for large and normal mode
appearance.titleTextAttributes = [.foregroundColor: .white]
appearance.largeTitleTextAttributes = [.foregroundColor: .black]
// No effect
appearance.buttonAppearance.normal.titleTextAttributes = [.foregroundColor: .white]
UINavigationBar.appearance(whenContainedInInstancesOf: [MyCiewController.self]).standardAppearance = appearance
So, setting different colors for large and normal title is no problem. However, I did not find any appearance property to do the same for the bar button items. My best guess was to use buttonAppearance but this had no effect.
How to make the "Done" button white in the normal nav bar? Is it possible to use appearances to solve this?
I have this view hierarchy on a view embedded in a UINavigationController:
When I scroll the UITableView the navigation bar is not moving up (the title is not becoming smaller) it stays like this:
If I remove the image view as background view everything works well.
My navigation is configured like this:
navigationItem.title = "Title here"
navigationItem.largeTitleDisplayMode = .always
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent
navigationController?.navigationBar.backgroundColor = .clear
A project demonstrating the problem is available here:
https://drive.google.com/file/d/181Aggala2ZfGN0lDjEtHWg0vobkM0iJc/view?usp=sharing
I already tried to change the insets of the tableview but it didn't work.
tableView.contentInset = UIEdgeInsets(top: navigationController?.navigationBar.height, left: 0, bottom: 0, right: 0)
Thanks!
As you discovered, to make large title fonts work as you want them to, the UIScrollView or any of its subclass needs to be the first element in the view hierarchy.
To fix your problem, you can try setting the background image to be the background of the UITableView directly.
Edit: Okay soo according to your comment you want a background behind everything including navigation bar. There is one way of achieving this and that is to subclass your UINavigationController and inside viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named: "wallpaper")
let imageView = UIImageView(image: image)
imageView.contentMode = .scaleAspectFill
imageView.frame = UIScreen.main.bounds
//this below part is important. Make sure to set it to 0 otherwise it will cover everything else
view.insertSubview(imageView, at: 0)
}
And then make sure your UIViewController containing the UITableView has a clear color for the UIView and remove the background image from that UIViewController
I add Left Navigation Menu Bar in JSQMessenger view controller.
myBackButton.addTarget(self, action: #selector(CustomerMessaging.popToRoot(sender:)), for: .touchUpInside)
myBackButton.setImage(UIImage(named: "navigationbar_image"), for: .normal)
myBackButton.setTitleColor(.white, for: .normal)
myBackButton.sizeToFit()
let myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
self.navigationItem.leftBarButtonItem = myCustomBackButtonItem
self.navigationItem.leftBarButtonItem?.tintColor = UIColor.white
I add back button image. The image is Blue back button. But, I set "White" color of tint color in Attributes Inspector. It changes into "white" in other view controller.
But for JSQMessengerViewController, I add above code. But it does not change into "White" color. Please anyone can help me?
This may be an issue with the image asset itself you can change it to a template type in your image.assets folder. or programmatically just change your image Rendering Mode
self.image = image.withRenderingMode(.alwaysTemplate)