7

I've already seen this post:

Can I embed a custom font in an iPhone application?

which is helpful, but I'd love to simply load the font via:

UIFont* font = [UIFont fontWithName:@"Harrowprint" size:20];

Some people have reported this possible but it's not working for me. Can someone confirm how to bundle a custom font with an iphone app?

Also, in the aforementioned post, one answer notes: The "name" of the font is not necessarily the filename.

How do I determine the "name" of the font that would be recognized by UIFont? It's possible i'm not using the correct name.

Community
  • 1
  • 1
Keith Fitzgerald
  • 5,651
  • 14
  • 43
  • 58

2 Answers2

13

There are several steps you need to take:

1) Make sure you have the rights to distribute the font. Most fonts -- even free ones -- do not allow you to distribute them. Putting them in your app most likely consitutes 'distribution' and would be considered illegal.

2) Copy the font to your Resources folder in your app. Make sure it's in your Copy Files build phase.

3) Add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension)

4) Get the 'name' of the font by putting in a temporary line of code:

NSLog(@"%@",[UIFont familyNames]);

Build and run the app. This will print to the Console the family names of all the fonts on the device. Find the one that matches your font.

You can then use that font name in the fontWithName: method.

rjmunro
  • 27,203
  • 20
  • 110
  • 132
August
  • 12,139
  • 3
  • 29
  • 30
  • Are you sure this is right? I tried doing this, and all I got was the normal list of fonts. – Sophie Alpert Mar 07 '09 at 21:36
  • Correct - it only prints out the name of standard fonts. Not custom ones. – 4thSpace Jun 14 '09 at 19:03
  • Excellent.. I had fonts in my App but never knew what could be the actual name of those fonts.. Thanks.. – rohan-patel Apr 12 '12 at 05:35
  • What do you mean by "Make sure it's in your Copy Files Build Phase." ?? – Talon Dec 19 '12 at 19:38
  • I'm not sure that it's "distributing" the font, I think it's "Embedding", like embedding in a PDF, unless your app lets people extract the font file or something weird. The right to embed is included in most free fonts, and can be bought for most commercial fonts, although you may have to pay extra or buy it separately. – rjmunro Jan 02 '13 at 11:35
  • number 4) fixed my problem! since the font name was not the same as font file name – CppChase Oct 25 '14 at 12:40
5

To add onto August's answer above, you need to add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension). Then the font will appear in the family printout and you can use that name to set the font.

Ned
  • 6,280
  • 2
  • 30
  • 34
  • Be careful when referring to other answers. Don't use words like above, below, previous or next as the order of answers can change due to voting, accepted answers, and user settings. I've edited your point into @August's answer. – rjmunro Jan 02 '13 at 10:50