Semyon Novikov
Semyon Novikov

Reputation: 271

How do I change UINavigationBar title label size?

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.

Upvotes: 1

Views: 6441

Answers (3)

George Sabanov
George Sabanov

Reputation: 189

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.

Upvotes: 0

Daniela Dias
Daniela Dias

Reputation: 98

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.

Upvotes: 0

Guntis Treulands
Guntis Treulands

Reputation: 4762

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!

Upvotes: 4

Related Questions