Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Font in ios not working

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!

like image 814
the Reverend Avatar asked Jul 08 '11 22:07

the Reverend


2 Answers

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.

like image 113
Ben G Avatar answered Oct 17 '22 07:10

Ben G


I think you're having the same problem I had : there's a bug in iOS where it is not able to use more than 2 fonts from the same family.

See blog post here for details and solution : http://www.pixeldock.com/blog/uifont-problem-when-using-more-than-2-custom-fonts-of-the-same-font-family/

like image 26
Thibault Martin-Lagardette Avatar answered Oct 17 '22 07:10

Thibault Martin-Lagardette