Reputation: 12907
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.
Upvotes: 7
Views: 2357
Reputation: 369
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.
Upvotes: 0
Reputation: 565
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.
Upvotes: 1
Reputation: 1573
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.
Upvotes: 8
Reputation: 113
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 :
Upvotes: 3
Reputation: 10475
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.
Upvotes: 3
Reputation: 18878
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];
Upvotes: 0
Reputation: 1380
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.
Upvotes: 1