0
votes

I've had hit-or-miss success with using custom fonts in an iOS app.

I follow these steps:

  1. Drag in the font into my project and copy into the project
  2. Make sure the font is included in the Build Phases
  3. Add the font name (including the extension) into the app's plist file. I confirmed that I am using the postscript name: SourceSansPro-ExtraLight.ttf
  4. Try to use the font

    self.daysLeftLabel.font = [UIFont fontWithName:@"SourceSansPro-ExtraLight" size:14];

However, only the generic system font is used.

If I run this code sample in my code:

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

The Source Sans Pro font family isn't included in this, so something isn't working.

The thing is, I followed the exact same sequence for other custom TTF fonts and they work as expected. As far as I can tell, I am doing everything right -- including the often-missed postscript name in the plist file along with the extension.

So, I'm beginning to wonder if some TTF fonts are compatible with iOS and some others aren't. Is this the case?

2
The info.plist needs to reference the actual filename, not the font name. And case matters in the filename.rmaddy

2 Answers

0
votes

I have the same issue too, you have to add actual filename in info.plist file instead of font name. while defining font in UILabel you have to use true font name.

1
votes

Severals reasons for this problem, you have to check the following:

  1. Make sure you ticked the checkbox for Copy Item into destinaton's group folder
  2. Make sure the font included in the target. You can check the Target Membership
  3. Check your file exists in bundle resources. Go To Target->Build Phases->Copy Bundle Resources
  4. Add your fonts in Application plist enter image description here

  5. Find font name. It may not be same as the file name. So you can use your for loop to find the font name.

    for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
    

    }

    Use this font name as

    label.font = [UIFont fontWithName:@"font-name" size:20];