Reputation: 3159
I've had hit-or-miss success with using custom fonts in an iOS app.
I follow these steps:
Try to use the font
self.daysLeftLabel.font = [UIFont fontWithName:@"SourceSansPro-ExtraLight" size:14];
However, only the generic system font is used.
If I run this code sample in my code:
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
}
The Source Sans Pro font family isn't included in this, so something isn't working.
The thing is, I followed the exact same sequence for other custom TTF fonts and they work as expected. As far as I can tell, I am doing everything right -- including the often-missed postscript name in the plist file along with the extension.
So, I'm beginning to wonder if some TTF fonts are compatible with iOS and some others aren't. Is this the case?
Upvotes: 0
Views: 275
Reputation: 11026
I have the same issue too, you have to add actual filename in info.plist file instead of font name. while defining font in UILabel you have to use true font name.
Upvotes: 0
Reputation: 6445
Severals reasons for this problem, you have to check the following:
Add your fonts in Application plist
Find font name. It may not be same as the file name. So you can use your for loop to find the font name.
for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
}
Use this font name as
label.font = [UIFont fontWithName:@"font-name" size:20];
Upvotes: 1