17

I know how to set the color and change the font for the large title in iOS 11, but I am having a hard time finding the default font and font size for the large title. I would like to reproduce the font elsewhere in the app. I have tried the following but they give no results for font or font size. Not sure where else I should be looking for this.

NSLog(@"self.navigationController.navigationBar.largeTitleTextAttributes:%@",self.navigationController.navigationBar.largeTitleTextAttributes);

NSDictionary *dict = self.navigationController.navigationBar.largeTitleTextAttributes;
UIFont *font = [dict objectForKey:@"NSFontAttributeName"];
NSLog(@"font is.. %@, %@, %@",font,font.fontName,font.fontDescriptor);
SAHM
  • 4,078
  • 7
  • 41
  • 77

7 Answers7

23

The proper solution for getting the large title font is the following:

Objective-C:

UIFont *font = [UIFont preferredFontForTextStyle: UIFontTextStyleLargeTitle];
NSLog("%@", font);

Swift:

let font = UIFont.preferredFont(forTextStyle: .largeTitle)
print(font)

This will give the correct value even if the user has applied various accessibility and font size changes in the Settings app.

The above will print out the following by default (in a playground):

<UICTFont: 0x7fa865c05390> font-family: ".SFUIDisplay"; font-weight: normal; font-style: normal; font-size: 34.00pt

Note that the use of .largeTitle in the code above must be called only with iOS 11. If your app supports iOS 10 or earlier, you must wrap that code in a proper use of @available.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
9

On iOS 13 this is the exact font that is used for large titles in navigation bars. I compared screenshots pixel by pixel and it matches exactly!

UIFont.systemFont(ofSize: 34, weight: .bold)
Tom van Zummeren
  • 9,130
  • 12
  • 52
  • 63
5

Edit: I opened the User Interface inspector and it says:

enter image description here

No need to code here :)

palme
  • 2,499
  • 2
  • 21
  • 38
  • And how does this answer the question? The question is asking what the default font and font size are for the large navigation title in iOS 11. This answer shows how to obtain the system (and bold system) font at 12 points. Not at all the same thing. – rmaddy Nov 09 '17 at 23:12
  • 1
    His wish was to "reproduce the font elsewhere in the app" and this could help him doing so. @rmaddy I changed the answer. – palme Nov 09 '17 at 23:21
  • 1
    @palme Your edit has the right answer. Please removed the wrong part and more people will upvote. –  Sep 03 '18 at 15:18
  • Good idea, I moved it to the top. – palme Sep 06 '18 at 03:27
4

iOS12 Large Title System Bold 34 (San Francisco)

[UIFont boldSystemFontOfSize:34]

iOS9 - iOS12 System Semibold 17 (San Francisco)

[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]

iOS8 System Semibold 17 (Helvetica Neue)

[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]

iOS7 System Bold 17 (Helvetica Neue)

[UIFont boldSystemFontOfSize:17];
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
  • iOS14, I got -> ` font-family: "UICTFontTextStyleTitle0"; font-weight: normal; font-style: normal; font-size: 34.00pt` – benc May 12 '21 at 03:27
3

Try something like this:

if #available(iOS 11.0, *) { navigationBar.largeTitleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont(name: "HelveticaNeue-Bold", size: 20)!] }

Marcos
  • 461
  • 6
  • 10
3

Easiest way is to use

UIFont.preferredFont(forTextStyle: .largeTitle)

Keep in mind, it's not UINavigationBar's large title, it's a style to use in your own views, that's why the weight is off. But you can apply intended weight to it.

UIFont(descriptor: normalTitleFont.fontDescriptor.withSymbolicTraits(.traitBold)!, size: normalTitleFont.pointSize)

Full code:

let normalTitleFont = UIFont.preferredFont(forTextStyle: .largeTitle)
let largeTitleFont = UIFont(descriptor: normalTitleFont.fontDescriptor.withSymbolicTraits(.traitBold)!, size: normalTitleFont.pointSize)

This approach is better compared to hardcoding sizes or fonts.

User can change accessibility settings on device and hardcoded values will be off.

The value of .largeTitle text style will change as well, and your title will get the the right style.

Andrei Konstantinov
  • 6,971
  • 4
  • 41
  • 57
0

I actually found the answer by trying different fonts and sizes. Now, a disclaimer, this may change with accessibility/dynamic font sizes. But the font and size I found was

[UIFont systemFontOfSize:32 weight:UIFontWeightBold]

I'd still like to find a way to get this programmatically and will wait to accept an answer in the hopes someone might know how to do that. In the meantime, hope this will be helpful to someone.

SAHM
  • 4,078
  • 7
  • 41
  • 77
  • See my answer. It actually is [UIFont systemFontOfSize: 36.0 weight: UIFontWeightBold] – palme Nov 09 '17 at 23:27
  • Not sure what app you are using, but I found the size my own app (in development) is using. I matched it perfectly by setting the largeTitleTextAttributes for the navigationBar on one Tab, then setting the title on that tab to the title of another tab that is using the default attributes, then playing with the attributes until the titles lined up perfectly. – SAHM Nov 09 '17 at 23:32
  • You are right. I highlighted the wrong label. The size is 34. – palme Nov 10 '17 at 09:55