开发者

ttf font not available for iPhone in interface builder or simulator

I added a font file (.ttf) to my Xcode project, to resources. Also, I added it to the UIAppFonts in my info.plist.

When I want to use this font though, I don't even see it as a choice in IB.

After installing the font on my system, I started seeing it in IB, but still - changing to it doesn't change anything - some default system font is displayed in the Interface Builder as well as in iPhone emulator.

Are ther开发者_StackOverflow中文版e any steps more I should do to be able to use my own font?


To use custom fonts with iOS you have to set them programmatically.

For example, suppose you have a font file called swellfont.ttf that you add to your project. You then would go into your App-Info.plist file and add the full name of the file to the next index of the array keyed by UIAppFonts, as you mention.

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

Then, to use the font:

label.font = [UIFont fontWithName:@"swellfont" size:12];

Assuming that label is a UILabel and that swellfont.ttf is not protected. It's important to note that UIFont's fontWithName is not referring to the filename, instead its wanting the actual name of the font. If you open the font with FontForge you can see this information by selecting Element > Font Info from the menu bar. There are probably cleverer ways to find this information out.


I use 2 fonts in an APP. The first one was automatically added to the "Copy Bundle Resources", the other was not. I had to add that one myself.

Call in code:

[labelName setFont:[UIFont fontWithName:@"OneGreatBigFont" size:40]];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜