1
votes

One I decide to make custom navigation bar design the right way. My navigation bar's title should be typed with custom font "Din Condensed" with size 23. So I wrote this code:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigation_background.png"]
                                 forBarMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setTitleTextAttributes:@{
                          UITextAttributeTextColor: [UIColor whiteColor],
                          UITextAttributeFont: [UIFont fontWithName:@"PFDinTextCondPro-Bold" size:23]
}];

But looks like title label can't fit text with this font:

title label size

How can I change size of UINavigationBar title using appearance API? I want to avoid using custom titleView.

3

3 Answers

4
votes

There is no way to change its font size. At least not as far as I know. The navigation bar will automatically resize the default title label's font size to fit either in portrait or landscape orientation.

Therefore you need a custom title view. But it's pretty simple; just need to set the navigation item's titleView to your label.

Example with multiple lines: UINavigationBar multi-line title

Example with single line but different font: https://stackoverflow.com/a/10171426/894671

Good luck!

0
votes

Have you tried setTitlePositionAdjustment to fix this problem? If this does not work I think the best way is for you to have a UILabel customized with the font you want and use it as titleView (custom view) attribute of navigation bar.

0
votes

Set title font in the storyboard.

  1. Inspect UINavigationController
  2. Open its UINavigationBar
  3. Set title font under title text attributes.

Now it shouldn't cut your title label.