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);
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With