7

I used a special font in my photoshop design,

  1. is it possible to use these fonts natively in the iphone app? or

  2. do I need to convert them into an image first?

  3. If this is the only way to do it, what do you do with dynamic text?

Kjuly
  • 34,476
  • 22
  • 104
  • 118
001
  • 62,807
  • 94
  • 230
  • 350

4 Answers4

30
  1. Copy your font file into Resources

  2. In your application .plist create (if it's exist just create a row) a row called "Fonts provided by application" and then in "item 0" copy your font name for example "Ciutadella-Bold.otf" (if there are some spaces in font name, rename it and for example replace all spaces to minus '-')

  3. Then you can define this font in your application:

    UIFont *CiutadellaBold = [UIFont fontWithName:@"Ciutadella-Bold" size:17.0f];
    
  4. And use in for instance in uiLabel:

    [uiLabel setFont:CiutadellaBold];
    
edzio27
  • 4,126
  • 7
  • 33
  • 48
  • 1
    I added my .otf fonts to the .plist and called them from the code programmatically. I also connected the label with the h file and can set the text. This seems to be the best way but what am I doing wrong? – Alex Cio Apr 12 '13 at 08:06
  • 3
    i just had to add the fond file to the target membership. Click the font file, and select in the menu on the right your project at the section "Target Membership" if not already selected. – Alex Cio Apr 12 '13 at 10:06
  • Step 2 seemed like it was necessary for me. Thanks! – Jared Egan Apr 21 '15 at 03:37
26
UIFont *font = [UIFont fontWithName:@"MyFont" size:20];
[label setFont:font];

Where "MyFont" would be a TrueType or OpenType file in your project (sans the file extension), and label would be an instance of UILabel.

Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
  • 16
    But be careful. Not always the name of the font file is the same with the font name. You can check the font name when installing the font on your computer. I'm telling this because I had this problem and spent hours to solve. – Slavcho Mar 26 '13 at 09:16
  • Thanks @SlavcoPetkovski, you saved me a lot of time! – Jeff Schmitz Apr 23 '13 at 20:09
4

Yes it is possible with iOS 3.2 and later. You need to have the fonts file, I forget what formats exactly. Add the font file as a resource to your project then add the names of the fonts in the applications info.plist in an array under the raw key 'UIAppFonts' or under the friendly key 'Fonts provided by application'.

Here's a sample application that you can look at - https://files.me.com/tobiasoleary/ey08n1. It prints out the all the fonts accessible to the application. Two fonts have been added Flames and Firestarter.

This is by far the easiest way to add custom fonts to application. If you need to support custom fonts for iOS before 4.0 see http://github.com/zynga/FontLabel/tree/master

This question has been asked before here: Can I embed a custom font in an iPhone application?.

Community
  • 1
  • 1
Tobias
  • 4,397
  • 3
  • 26
  • 33
0

Note :

The parameter of “fontWithName” must be the real name of the font, not the name of the file. If you open your ttf file with the Mac Font Book, you will directly see its name on top of the window.

Ayman
  • 175
  • 1
  • 13