0

I am customising UINavigationBar with different color and custom font by using titleTextAttributes. However, when I moved to another view, I would like to use different color from previous with same custom font.

I have used,

[[UINavigationBar appearance] setTitleTextAttributes:mySettings]

in AppDelegate.m. When call same method with newSettings in viewDidLoad of another viewController, it doesn't get reflected.

I am able to change bar color or bar tint color in viewDidLoad of another viewController. However, my title foreground color is not changing. Am I missing anything?

Last solution which I have to have custom titleView. But wanted to avoid it. Any inputs?

Abhay
  • 118
  • 1
  • 5

1 Answers1

0

[[UINavigationBar appearance] setTitleTextAttributes:mySettings] is a global configuration, so that's the reason why changing it in the other view controllers doesn't work. I believe you won't getting around customizing the titleView property of navigation item,... :/

You can do this by creating a UILabel that has the settings that you want and then assign it to the property:

 NSAttributedString *title = [[NSAttributedString alloc] string:"the title" attributes:mySettings];
 UILabel *newTitleView = [[UILabel alloc] init];
 newTitleView.attributedText = title;
 self.navigationItem.titleView = newTitleView; 
nburk
  • 22,409
  • 18
  • 87
  • 132
  • Thanks @nburk. I have changed the code to use label as titleView. Secondly, as there are many views where such changes are required, created category for UINavigationController. I had issue with navigationController.navigationItem Vs. UIViewController.navigationItem for setting titleView. This link helped me http://stackoverflow.com/questions/16913332/navigationcontroller-navigationitem-vs-navigationitem – Abhay Oct 08 '14 at 06:33