Reputation: 4685
I know how to change the UINavigationBar's title font properties by using this code:
[self.navigationController.navigationBar setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:16.0f], UITextAttributeFont, nil]];
However, I am finding that when I change the font size in this way it effects all views, not just the view in which I am implementing the above code. The problem is, I want to change the size for just 2 views that have long titles. The other views (including the root view) I wish to retain the default setting for font size. I've tried changing the font size back to normal in the viewDidLoad
method using the above code, but it does not work.
Is there a way to change the title font size for just certain views? Thanks.
Upvotes: 2
Views: 1981
Reputation: 6667
You should call that code in each view controller's viewWillAppear:
method. When you set it in viewDidLoad
, the setting gets overridden by the next view controller's actions. You might also have to call setNeedsDisplay
on the navigationBar to refresh it (although I don't believe so).
Like so:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:16.0f],
UITextAttributeFont,
nil]];
}
Upvotes: 7