4

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.

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.

jlindenbaum
  • 1,891
  • 18
  • 28

4 Answers4

17

Open the font in Fontbook (It ships with your mac). Make sure you call it by the post-script name, like here: enter image description 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.

Oscar Apeland
  • 6,422
  • 7
  • 44
  • 92
  • Thanks! Yes, the names match the PostScript Name in Fontbook. Both font files are part of the target, and in the plist. Still doesn't work on devices. Just the simulator. – jlindenbaum Sep 25 '13 at 19:19
  • @jlindenbaum Is it the case with all fonts, or just these two? – Oscar Apeland Sep 25 '13 at 21:06
  • Proxima is showing up when I print out the family and available names on the device, DS-Digital does not. – jlindenbaum Sep 25 '13 at 21:09
  • You said they both log in your original question - do they or not?:) Have you tried to just delete the app from your bundle and adding it again? I'm pretty clueless, but you could try the way I would've done it. I'd make a new clean project with just a label, try to add the font etc, to see if its your project, the font, xcode, or where the fault is. I find it easier to troubleshoot without all the possible factors that MIGHT be messing it up. – Oscar Apeland Sep 25 '13 at 21:13
  • 1
    Thanks Oscar, it ended up being a combination of bundling the font and using the proper name. Once we fiddled around with that enough it finally worked. – jlindenbaum Oct 22 '13 at 16:39
  • A good thing to note here is that when new fonts are added, it's a good idea to uninstall the app from your device (or reset your simulator) to make sure the new fonts copy over in the bundle. – d2burke Feb 06 '14 at 00:05
0

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

Community
  • 1
  • 1
Georg
  • 3,664
  • 3
  • 34
  • 75
0

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

GroovyCarrot
  • 514
  • 3
  • 6
0

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?

Corey
  • 5,818
  • 2
  • 24
  • 37
  • In my question you can see I assign the font to labels with `setFont:[UIFont fontNamed:@""]` When I run this on the simulator I see both fonts printed out in the console. On device I see proxima, but I don't see the DS-Digital, despite both being in the copy resource, and target. – jlindenbaum Sep 25 '13 at 20:01
  • Sorry, I understood that you were setting the font to the labels. My question was about where in your code are you setting the fonts. In `viewDidLoad:`,`viewWillAppear:`? Did you get this font from dafont? I just downloaded that font (DS Digital), renamed it to 'digifont-italic.ttf' and included it in an app with no problem. If it's not showing in your list of fonts, there has to be a breakdown in the build phase or plist. Try deleting the font and try adding it again. Otherwise, create a new project, and re-import everything. – Corey Sep 25 '13 at 22:06