Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 there any steps more I should do to be able to use my own font?

like image 367
kender Avatar asked Dec 21 '10 10:12

kender


People also ask

How to add font to iOS project?

To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.

How to add custom font to Xcode 13?

Add the font file to your Xcode projectSelect File menu > Add Files to "Your Project Name"... from the menu bar, select all the fonts you need to add, then click the Add button. Or drag the file from Finder and drop it into your Xcode project. Drag the font files from Finder and drop it into your Xcode project.


1 Answers

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.

like image 160
Allyn Avatar answered Sep 29 '22 13:09

Allyn