How to include and use new fonts in iPhone SDK?

I want to use font "MgOpen Modata" in my iphone App. But I dont see it in the font list in Property inspector.

How do I include that font so that I can use it?


Solution 1:

  1. Add the font files to your resource files
  2. Edit your Info.plist: Add a new entry with the key Fonts provided by application.
  3. For each of your files, add the file name to this array

On the example below, I've added the font "DejaVu Sans Mono":

Info.plist: adding custom fonts

In your application you can the use [UIFont fontWithName:@"DejaVuSansMono-Bold" size:14.f].

Or if you want to use it in html/css, just use font-family:DejaVu Sans Mono;

Note: this is available in iOS 3.2 and later.

Solution 2:

I found this walkthrough was the best

Although the above accepted answer does work I found that if you added text into an XIB file and then set the font to our new font then the text didn't update.

Making sure the new font is included in resources fixed this problem (taken directly from walkthrough):

"This should not be a problem but sometimes when you’re having trouble getting your font face to show up, this can be a source of headache so let’s double check now to rule it out as a potential pitfall.

Go to your project Build Phases pane by highlighting the XCode project file in your solution explorer and on the right hand side, select “Build Phases”. You’ll see that one of the sections you can expand is “Copy Bundle Resources”. Open that list and make sure that your fonts are included in that list."

Make sure the fonts are included in our resources

The other stuff in the walkthrough is the same kind of stuff (add the file to your project and to the plist file too)

All credit to Code with Chris for this answer which saved me a lot of time and effort and I am merely copying a shot from his page to allow this answer to stand on its own feet instead of requiring you to click the link.

Solution 3:

Don't forget to add the fonts to the targets compile bundle resources by going to 'Targets' -> 'Build Phases' -> 'Copy Bundle Resources' and add all the fonts manually