Today, I will write a small tutorial about how to add a custom font to an iOS app (version 4.0 and up only).
Every version of iOS comes with a list of common fonts (e.g. Verdana, Arial, Helvetica, etc.). The problem with that list is that older versions of iOS don’t support all the fonts. So, if you want to use a font that has been added with iOS 5, users with iOS 4 will not see it. Another fact is that lots of iOS apps are simply using the “System” font which is the font by default!
The solution for that is to add your fonts to your app, so you will have a unique app design. To do so, simply follow these steps:
- Add your font files to your project in XCode (The files should appear as well in “Target -> Build Phases -> Copy Bundle Resources”).
- In your “Info.plist” file, add the key “Fonts provided by application” with type “Array”.
- For each font you want to add to your project, create an item for the array you have created with the full name of the file including its extension (e.g. myfont.ttf).
- Save your “Info.plist” file.
Now, in your code, you can simply call your custom font like this:
[UIFont fontWithName:@"MyFont" size:50.0];
WARNING : 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.
A nice place where to find lots of custom fonts is DaFont.
I have created a small sample project that you can download on GitHub.