7

I'm trying to use fonts from the Open Sans family. I added the fonts to my Xcode project, I checked that they were added to my application's resources bundle and I added the fonts to my Info.plist file.

When I edit a XIB in Interface Builder, I can use Open Sans font on UILabels when selecting Custom in the font dropdown menu. The font are correctly rendered on the preview in Interface Builder, but then when I launch the application on the device, the font is not applied to the labels.

I tried setting the font programmatically, but that didn't work either. And I'm not getting any warning nor error.

What did I forgot to be able to use a custom font?

The behavior has been the same on an iPad Air running iOS7 and on an iPhone 6 running iOS8.

8
  • Maybe this is the localization issue? Does your custom font support all languages you are running? Commented Mar 30, 2015 at 15:36
  • @Azat How so? Also, french and english for now. Commented Mar 30, 2015 at 16:11
  • I was facing same situation when tried to use some custom font. It was OK in English but in my native language it was like default one Commented Mar 30, 2015 at 21:21
  • Having same issue :/ Also did all the usual steps everyone suggests.... Commented May 3, 2015 at 17:10
  • 1
    @AbbasAngouti Sadly not, that was a while ago and I've dropped that font since. Commented Apr 14, 2016 at 14:47

7 Answers 7

8

Go to Target -> Build Phases -> Copy Bundle Resources , in there you check if the font file is there, if not press the plus button and add it manually. Sometimes the font files are not added automatically to the bundle resources.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

3

Just make sure all the fonts really are available in the bundle, try printing all fonts and check if you are using the correct name. You can very easily do this with following code in app delegate's didFinishLaunchingWithOptions method:

for (NSString *familyName in [UIFont familyNames]) { NSLog(@"Family Name : %@", familyName); for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"\tFont Name : %@", fontName); } } 

or in Swift:

if let familyNames = UIFont.familyNames() as? [String] { for familyName in familyNames { println("Family : " + familyName) if let fontNames = UIFont.fontNamesForFamilyName(familyName) as? [String] { for fontName in fontNames { println("\tFont : " + fontName) } } } } 

The swift code is not the most efficient, but should work for checking if the fonts exist in the bundle.

Comments

3

What worked for me was when I added the font to check the "Add to targets" thick in front of my app name.

See image example here :

enter image description here

2 Comments

can you provide more details ?
hey, I edited my answer, that is the dialog you are prompted with when you add the font to your app
1

Ensure you have added the fonts in your Info.plist. There is an entry called "Fonts provided by application" which must contain all font files you want to use.

2 Comments

Sorry I forgot to mention it, but that was done. So that's not that apparently.
If the fonts are showing up in Interface Builder, they are clearly valid fonts. Are you sure the font isn't being overridden somewhere in your code to something you aren't expecting? Can we see the code you're using?
1

I just had the same problem... still kind of having... I wanted to mix fonts in the same label, which did not work... The workaround was that I tried to change in the IB attributes inspector of the label try to change Text dropdown from Attributed to Plain... The font did change in the device... so I think this is a bug in Xcode.

Comments

0

Are you adding the font to your info.plist exactly how the font is spelt with the inclusion of its file extension? For example, OpenSans.ttf is different than opensans.ttf or just opensans. To be 100% sure of the file name right click on your font file, click on Get Info, and then check the Full Name description. To add the font programmatically leave the file extension off. For example,

myLabel.font = [UIFont fontWithName:@"OpenSans" size:32]; 

2 Comments

Did all that, nothing changed.
Have you tried deleting the application from your device/simulator, cleaning the project, then reinstalling?
0

If you are using webfont then download.ttf file and drop it into your project . Check mark on copy items if needed

Next add this on info plist

 <key>UIAppFonts</key> <array> <string>Your fontname.ttf</string> <string>Bakersfield Bold.ttf</string> </array> 

Now take a look the font family name. Which you will find on font file also. From where you have downloaded you will get there also. Like i added font which ttf file name is : Bakersfield Bold.ttf for this fontname is : Bakersfield-Bold Thats it Happy coding.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.