简体   繁体   中英

Change UINavigationBar Font SIze for Select Views

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.

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]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM