UINavigationBar custom font does not work on iOS 8

I spent several hours using a custom font for the navigation bar title on iOS 8. This works fine on iOS 7:

UIFont *font = [UIFont fontWithName:@"Gotham-Bold" size:12]; NSDictionary *textAttributes = @{ NSFontAttributeName: font }; self.navigationController.navigationBar.titleTextAttributes = textAttributes; 

But on iOS 8, the text just disappears. Changing the color or size of the system font works fine, but trying to use a custom font will not work at all. Does anyone know about this?

Thanks!

EDIT

I created a small project so you can try it yourself: https://github.com/noquepoaqui/customHeaderFont

These lines of code are on the MasterViewController on line 30.

+7
objective-c ios8 uinavigationbar
source share
2 answers

You have a typo when you assign attributes:

It should be:

 self.navigationController.navigationBar.titleTextAttributes 

instead:

 self.navigationController.navigationBar.titleTextAttributes 

If this does not fix the problem, you can check if the font was added correctly by placing this code in AppDelegate didFinishLoadingWithOptions . This will print all available fonts of your application. Just look at the output window and find the name of your font (Gotham-Bold). If it is not specified, you can remove the font from your project and add it again using drag and drop. Be sure to check "add to target" next to your application in the dialog box that appears.

 //list all available fonts for (NSString *family in [UIFont familyNames]) { NSLog(@"---------- %@ ----------", family.uppercaseString); NSArray *names = [UIFont fontNamesForFamilyName:family]; for (NSString *font in names) NSLog(@"%@", font); } 
0
source share

The .ttf font I used worked poorly. I installed the .otf version and everything works fine.

0
source share

All Articles