1

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.

Semyon Novikov
  • 261
  • 4
  • 10

3 Answers3

4

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!

Community
  • 1
  • 1
Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72
0

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.

shim
  • 9,289
  • 12
  • 69
  • 108
0

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.

George Sabanov
  • 179
  • 1
  • 8