Question

I cant get my .ttf file to work in my iPhone app. I added this file to my project:

gothamnarrowbook.ttf

I added this to my plist:

<key>UIAppFonts</key>
<array>
    <string>gothamnarrowbook.ttf</string>
</array>

And in my ViewController, I added this:

UIFont *gnb = [UIFont fontWithName:@"gothamnarrowbook" size:22];

But gnb is nil. What am I doing wrong?

Was it helpful?

Solution

Unfortunately, the actual 'name' of the font you reference in the .plist isn't necessarily the same as its file-name.

To find out the real name of the font, open it in Font Book, and you should be able to see it's real name. Maybe the actual name is "Gotham Narrow Book", or something like that, Font Book will tell you.

Check out this blog post to find out more.

Also note that:

Using the name from Font Book works well enough for fonts with one variant, but if your font has multiple variants, and you don't want to get involved with iOS's seemingly incomplete implementation of NSAttributedString, then you'll have to specify the variant explicitly when you load the font.

Using UIFont's class method +fontNamesForFamilyName: you supply the font family name, for example "Cloister Black" which might have two variants "Light" and "Dark", and it will return an NSArray of all variants of that font, "CloisterBlack-Light" and "CloisterBlack-Dark". Notice no spaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top