iOS Font Name Problem

I wanted to followup my previous post about iOS font positioning with something else I came across yesterday.

While adding a custom font to a new app there was a problem with the font not appearing in the simulator or on device. It had been added correctly to the .plist, included in the project and i’d checked Font Book to make sure I was using the correct name in the ‘[UIFont fontWithName:name size:size]’ command. Even though everything seemed correct the font just would not show.

I decided to find out what fonts were installed (to check it was there) by adding the following code to my app delegate:

for (NSString *familyName in [UIFont familyNames])
{
    NSLog(@"----------------");
    NSLog(@"FAMILY: %@", familyName);
    for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
    {
        NSLog(@"  %@", fontName);
    }
}

This outputs into the debug window the name of all the fonts included in the app, including the name of my custom font. As it turns out from the debug window the font wasn’t called ‘Frutiger CE 65 Bold’ as was reported in Font Book but was actually called  ‘FrutigerCE-Bold’ (at least as far as iOS is concerned) as such I changed the code to the following and the font worked perfectly!

[UIFont fontWithName:@"FrutigerCE-Bold" size:16.0f]

So if you add a custom font and it doesn’t seem to work then i’d recommend the above method to solve it. If anybody else knows why this is the case (I didn’t have time to look in it) please leave a comment.

 

3 Comments

  1. Pingback:Custom iOS fonts and how to fix the vertical position problem | Andy Yardley

  2. Awesome. Very useful piece of code. Thanks!

  3. nice one, helped me out!

Leave a Comment

Your email address will not be published. Required fields are marked *