iphonemaclover iphonemaclover - 3 months ago 29
Objective-C Question

Custom Font no display in IOS (.otf type)

My below San Fransico font not working
Download here and test

I have added all the otf file in the .plist and use the name to set font in the code using font manager as below

lbl_1.font = [UIFont fontWithName:@"SFUIDisplay-Bold" size:20];
lbl_2.font = [UIFont fontWithName:@"SFUIDisplay-Medium" size:20];
lbl_3.font = [UIFont fontWithName:@"SFUIText-Light" size:20];
lbl_4.font = [UIFont fontWithName:@"SFUIText-Regular" size:20];
lbl_5.font = [UIFont fontWithName:@"SFUIText-Semibold" size:20];

NOTE: I download the .ttf and its working using Zil answer

Zil Zil

There are common mistakes to fonts not working, let me list them all and I'm sure you'll find your issue :

  • Make sure you've added the fonts in your project, and that you can see them in XCode. You could put them in the root folder or in a specific folder.

  • Make sure they've the correct target, or that they actually have a target at all ;) Tick the box and you're good

Look at this image for point 1 & 2. fonts are in the right folder and have correct target

  • Make sure your image is included as Resources of your current bundle :

enter image description here

  • Make sure you reference them in your .plist file, if they're in a cusotm folder, i'm pretty sure you need to write down the relative path, not only the name.

enter image description here

  • Make sure you're using the correct font name, that you can find using the following code snippets :

Objective-C :

for (NSString* family in [UIFont familyNames])
    NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
        NSLog(@"  %@", name);


for family: String in UIFont.familyNames()
     for names: String in UIFont.fontNamesForFamilyName(family)
         print("== \(names)")

Don't forget to remove that code after you're done. This will help you make sure you're indeed using the correct family name for the font, which can sometime vary from the actual name you see using the Font viewer of OSX.

Note : if your fonts dont' print, that means they're not in the project, if they print, that means you didn't succeed into loading them, but that they're in the project. This specific step could help you pinpoint the problem.

enter image description here

  • Actually use the font :

    UIFont myFont = [UIFont fontWithName:@"QuicksandDash-Regular" size:35];

Thanks to Chris for the actual tips

I'm 100% sure the correct answer is somewhere in here, so make sure that everything is correct on your end. Unless you've done something specificly against using fonts, repeating these steps should be enough. You could try using an empty project and compare the results, which often helps when encountering "unresolvable problems"