开发者

My custom font is not displaying

I'm trying to use a custom font in my iPhone app.

I created a key for it in my info.plist as follows:

<key>UIAppFonts</key>
<array>
        <string>CloisterBlack.ttf</string>
</array>

and I'm accessing the font like this:

[UIFont fontWithName:@"CloisterBlack" size:64.0]

but the font is not displaying. What could be the r开发者_开发百科eason?


Make sure you give the real font name in above code. The font file name and its “real font name” can be different, so just open the font in FontBook app and there you can see the real name of the font.


The "Real Font Name" is not always the one you see in Fontbook. The best way is to ask your device which fonts it sees and what the exact names are.

I use the uifont-name-grabber posted at: http://forgecode.net/2010/08/uifont-name-grabber/

Just drop the fonts you want into the xcode project, add the file name to its plist, and run it on the device you are building for, it will email you a complete font list using the names that UIFont fontWithName: expects.


  1. Add Font info in info.plist
  2. Find name of font, by printing names of available fonts. You can do that with piece of code:

    NSArray *fontFamiliesTemp = [UIFont familyNames]; for (int i = 0; i < [fontFamiliesTemp count]; i++) { NSString *fontFamily = [fontFamiliesTemp objectAtIndex:i]; NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]]; NSLog (@"%@: %@", fontFamily, fontNames); }

  3. Search for your font in printed results. After that you only need to use that font name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜