I have a list of font names in my app, which are all displayed in the font they represent. The following three do not work though:
ArialRoundedMTBold
ChalkboardSE-Bold
TrebuchetMS-Bold
Instead they display in the standard font.
Any ideas why these might not be showing up?
I was using a Google font named Arvo. It had the following files:
Arvo-Regular.ttf Arvo-Bold.ttf Arvo-BoldItalic.ttf Arvo-Italic.ttf These names were added into my app's info.plist but for some reason, my app could only read the bold, bolditalic, and italic fonts. It couldn't read the regular font when i tried to load it. However, after printing out the font names, it came out that Arvo-Regular was recognized as Arvo in my app.
Open Font Book application. If you installed the fonts yourself, go to user, look for the fonts you want and use the PostScript name of the font in your xcode project.
It should work even for different font variations of the same family.
How to configure a custom font
To use a custom font (one not included in iOS) you have to edit your
<appname>-Info.plist
file and create a newUIAppFonts
key with type array, where each element of the array is a String with the name of your font file. Example:VAGRoundedStd-Light.ttf
. You also have to add the file to your project.Note: When you type
UIAppFonts
and press enter, the key is converted to "Fonts provided by application".However, when you use the font in Interface Builder (or with
UIFont
) you don't use the filename of the font, but the name that appears when you open the font in the application Font Book of your Mac. For the previous example it would beVAG Rounded Std Light
.OS X is more tolerant than iOS digesting TrueType formats, so on rare occasions you may find a font that works in OS X but not in iOS. If that happens, replace the font to see if at least you got the process right.
How to load a font programmatically
This solves the case where the font license requires you to distribute the font encrypted.
This following recipe is from Loading iOS fonts dynamically by Marco Arment. It makes the fonts available in UIFont and UIWebView. The same code can be used to load fonts from the Internet.
How to load more than two fonts of the same family
This is the case where iOS refuses to load more than two fonts from the same family.
Here is a code workaround from stackoverflow user Evadne Wu. Simply stick the following in your app delegate (note that it uses two frameworks):
Available as gist. Commented in the author blog: Loading 2+ fonts on iOS from the same font family.
An alternative, more involved workaround from pixeldock.com:
If you see this happening, it is a limitation of your SDK version, and the only way out of it is editing the font family with a Font editor like Fontforge. Again, from pixeldock.com:
I had a similar issue with not finding Chalkduster - even though IB listed it as a font and it's listed as an IOS font. I discovered that the list of fonts on iPhone and iPad is not identical.
Chalkduster is available for iPad but not iPhone. Chalkboard is available on iPad 4.x but not 3.x. It is available on iPhone 3.x & 4.x.
More details here: http://www.whatsyourdigitaliq.com/2011/05/11/fonts-available-in-various-versions-of-ios/
Only a subset of Mac OS fonts are available in iOS. If you set a font that is not available, it will be displayed as the standard Helvetica.