Custom Font in ios not working

the Reverend picture the Reverend · Jul 9, 2011 · Viewed 44.1k times · Source

I want to use HelveticaNeue-UltraLight in my ios application. I'm adding the font file as a resource to my project and adding the "Fonts provided by application" key in the plist file. The file name is HelveticaNeue.dfont and I've added it to the key array.

When I check for the available fonts I can see it now...

  NSArray *fonts = [UIFont fontNamesForFamilyName:@"Helvetica Neue"];

for(NSString *string in fonts){
    NSLog(@"%@", string);
}

1-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-Bold
2011-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-CondensedBlack
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue-Medium
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-Light
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-CondensedBold
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-LightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLight // HERE IT IS!
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-BoldItalic
2011-07-08 17:32:57.870 myApp[5159:207] HelveticaNeue-Italic

But when I try to get it with [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:12] I just get HelveticaNeue-Light..

I'm getting no errors or warnings. Help please!

Answer

Ben G picture Ben G · May 3, 2012

Not only does the file needs to be added to the project, but it needs to be added to the target as well.

Sometimes (as in my case), when drag and dropping the ".ttf" file in Xcode, the "add to target" is not checked. This means the file is actually visible in your project, but it is not embedded in the app.

To make sure it is:

  • Click on the project's name (left pane)
  • Then on the target (middle pane)
  • Then "Build Phases" (third tab on the right pane)
  • Then "Copy Bundle Resources"

You should see the font file in that list.