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 UILabel
s 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.
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.
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.
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With