Reputation: 1881
I've combed SO for similar problems, and most of them seem to tell me that I've probably forgotten to add the font into the copy resources build phase. I've also made sure that both fonts are part of the build target.
I've double, and triple checked that. Both fonts are in the copy resources phase, and both are listed in the plist.
In my app delegate I check which fonts I have available for their respective font families, and I'm getting unexpected results
NSLog(@"%@", [UIFont fontNamesForFamilyName:@"DS-Digital"]);
NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Proxima Nova"]);
The first prints out "( "DS-Digital-Italic" )" which is what I wanted, the second prints out " ( "ProximaNova-Regular") ", also expected.
When I go to use either of the fonts as follows, it only appears in the simulator, but on any device it defaults back to system font.
[_estimateLabel setFont:[UIFont fontWithName:@"DS-Digital-Italic" size:50]];
or
[cell.mainLabel setFont:[UIFont fontWithName:@"ProximaNova-Regular" size:20]];
Is there anything I'm missing? I am using XCode 5 with an iPad mini and an iPhone 5C, both iOs 7.
Upvotes: 3
Views: 4352
Reputation: 6662
Open the font in Fontbook (It ships with your mac). Make sure you call it by the post-script name, like here:
Its called by @"HelveticaNeueCE-Thin"
Also make sure that you checked the name of your font in "Add to targets:" when you added them to the project, if you didn't do this, they won't be copied in the app bundle sent over to your iDevice.
Upvotes: 16
Reputation: 5818
Run this in your AppDelegate to see if the font family and name appear when running on the device:
for (NSString *family in [UIFont familyNames]) {
NSLog(@"%@", family);
for (NSString *name in [UIFont fontNamesForFamilyName:family]) {
NSLog(@"\t%@", name);
}
}
If the font family and names DO appear and the spelling is accurate, then perhaps there's an issue with the font file...? Take a look at the Device Logs (or Console) to see if there are any errors using the file.
Is it possible that the font could be overridden somewhere else in the code or even from interface builder? Where are you setting the font?
Upvotes: 0
Reputation: 514
I write programatically so I don't know if there is an easier way in XCode, I don't even develop on a mac but I load custom fonts like so:
// Load font
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:@"/path/to/font.ttf"]);
CGFontRef uiFont = CGFontCreateWithDataProvider(fontDataProvider);
NSString * uiFontName = (__bridge NSString *)CGFontCopyPostScriptName(uiFont);
CGDataProviderRelease(fontDataProvider);
CFErrorRef error;
CTFontManagerRegisterGraphicsFont(uiFont, &error);
CGFontRelease(uiFont);
UIFont *yourfont = [UIFont fontWithName:uiFontName size:20.0f];
I'm guessing XCode has a way to do it for you but that's always an option if you just want a snippet of code that works
Upvotes: 0
Reputation: 3930
Did you make sure you got the font name spelled correctly? See this post Can I embed a custom font in an iPhone application? for reference
Upvotes: 0