5
votes

I'm trying to use this font in my project but it won't work. I added the .ttf file in my project and added its name in the MyApp-Info.plist under the key: Fonts provided by application. Then I tried this:

 [_titleLabel setFont:[UIFont fontWithName:@"chalkboard" size:_titleLabel.font.pointSize]];

I also checked if the name of the font is really "chalkboard" and it is. The displayed font is still Helvetica, only smaller. Where could the problem be? Thanks in advance.

6
I've been having this problem since moving to Xcode 4.3 as well. No matter what I do, custom fonts don't install.Tim Sullivan

6 Answers

32
votes

You need to use font name, not filename. Font name is inside the ttf file.

You can find font names for iOS here: http://iosfonts.com/

This code will list all your font names in your app, put it somewhere in viewDidLoad on main controller, run app and then in console found the right name for the font.

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];

NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
    fontNames = [[NSArray alloc] initWithArray:
                 [UIFont fontNamesForFamilyName:
                  [familyNames objectAtIndex:indFamily]]];
    for (indFont=0; indFont<[fontNames count]; ++indFont)
    {
        NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
    }
}

Upd.

You can also right click on font file in Finder, get Info and copy full name. But it is not always 100%.

24
votes

Flinks answer is a handy tool to check if your fonts are loaded properly.

Do the following:

[_titleLabel setFont:[UIFont fontWithName:@"chalkboard" size:_titleLabel.font.pointSize]];

Make sure your fonts are included in your bundle:

  • Click your project
  • Go to build phases
  • Under 'Copy Bundle Resources', make sure your fonts are included

Worked for me :)

3
votes

Xcode 4.3.1 Custom Font have problem. Because when i create new project and try to add custom fonts in Xcode 4.2.1 there is no problem.

I did several times. Interesting...

1
votes

Its my experience that not "all" fonts are compatible. Most work, but you will run into a few fonts that just for some reason will not be recognized through code no matter how hard you try... Just a heads up for anyone having issues, just try another font!

1
votes

  1. Include your fonts in your XCode project
  2. Make sure that they’re included in the Target Membership in File Inspector tab
  3. Include you font in Project Name > Build Phase > Copy Bundle Resources
  4. Include your iOS custom fonts in your application plist. Add a new row called “Fonts provided by application” and put your font name and extension as parameter.
  5. Find the name of the font.
  6. Use UIFont and specify the name of the font.

    UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 290, 300, 30)];
    headingLabel.text = @"WELCOME";
    headingLabel.font = [UIFont fontWithName:@"Arvo" size:14.0];

http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
0
votes

Not All Font's you imported are working. Just try to test into another font. If it works then it is not recognized by Xcode. Just remember that it must be in your project plist file and it has to be a extension name like ".otf" or ".ttf" in plist. And also add it in "Copy Bundle Resources" under target