ngoue
ngoue

Reputation: 1055

UINavigationController Title Not Using Correct Tint

I've adjusted the default tint of my navigation bar to be white and it appropriately adjusts the color of each of my navigation bar elements:

Navigation bar with appropriately tinted elements

However, when I push to a new view controller and try to set the title property, the tint is no longer applied:

Navigation bar with inappropriately tinted title

I know that I can supply a label or something similar to the titleView attribute of my view controller that would do the trick, but that's a lot of work (relatively speaking) and in my mind the text should just default to the navigation bar's tint color. Am I missing something else? Or is this standard behavior that requires a custom titleView to override?

Upvotes: 0

Views: 177

Answers (2)

Ibrahim
Ibrahim

Reputation: 1

No you work correctly. But you should to set color for second view. You can use this code to solve your problem. In second view write this code to set color and font for your navigation title.


navigationController!.navigationBar.titleTextAttributes = ([NSFontAttributeName: UIFont(name: "Helvetica", size: 25)!,NSForegroundColorAttributeName: UIColor.white])


Upvotes: 0

JAB
JAB

Reputation: 3235

The tint property does not affect the color of the title. To set the title color (along with other attributes like font) globally, you can set the titleTextAttributes property of the UINavigationBar appearance to suit your needs. Just place this code in your AppDelegate or somewhere else appropriate that gets called on launch:

Swift 3:

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

Swift 2

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]

Upvotes: 2

Related Questions