How would I go about changing the color of the UINavigationBar
in Swift?
Most things online say to do something like:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
Which I translated to
let titleDict: NSDictionary = ["NSForegroundColorAttributeName": UIColor.whiteColor()] self.navigationController.navigationBartitleTextAttributes = titleDict //self is referring to a UIViewController
But it doesn't work. I already changed the background and button colors, but the text color doesn't change. Any ideas?
The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color. navbar-dark: This class will set the color of the text to light.
The tint color to apply to the navigation bar background.
Use NSForegroundColorAttributeName
as key, not "NSForegroundColorAttributeName"
string.
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()] self.navigationController.navigationBar.titleTextAttributes = titleDict
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With