Add Custom Font

iPhone SDK Tips & Tricks

  1. Add your font file (for example, Chalkduster.ttf) to Resources folder of the project in XCode.
  2. Open info.plist and add a new key called UIAppFonts. The type of this key should be array.
  3. Add your custom font name to this array including extension ("Chalkduster.ttf").
  4. Now you can use [UIFont fontWithName:@"Chalkduster" size:16] in your application.

Unfortunately, IB doesn't allow to initialize labels with custom fonts.

myLabel.font= [UIFont fontWithName:@"Chalkduster" size:18];


Sometimes font name is different from filename, you can check the correct font name with this:

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]);

}

[fontNames release];

}



For xcode 4.3 or later, 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