Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar Text Color in Swift

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?

like image 862
cclloyd Avatar asked Jun 25 '14 06:06

cclloyd


People also ask

How do I change the color of my navigation bar text?

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.

What is barTintColor?

The tint color to apply to the navigation bar background.


1 Answers

Use NSForegroundColorAttributeName as key, not "NSForegroundColorAttributeName" string.

let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()] self.navigationController.navigationBar.titleTextAttributes = titleDict 
like image 52
Kreiri Avatar answered Sep 29 '22 04:09

Kreiri