简体   繁体   中英

iOS custom fonts not working

I'm trying to use this font in my app. I've added it to the plist and to the project, but for some reason it is not loading on the label. I've tried to verify the font in the project with:

NSLog(@"DK Crayon Crumble: %@",
          [UIFont fontNamesForFamilyName:@"DK Crayon Crumble"]);

But I'm getting this output:

DK Crayon Crumble: ( )

I found the problem. For some reason Xcode it was not copying the font file to the bundle package.

The convention with the built-in fonts (you can select them in Interface Builder) is that you eliminate the spaces and add the attributes after a hyphen, such as

@"HelveticaNeue-Bold"

for Helvetica Neue, Bold .

I don't know the exact name of your font but if you follow this scheme, it should work.

Some times the fonts are visible in the project file but are not actually added to the target to do so

click on the project's name -> click on target -> Build Phases, go to

'Copy Bundle Ressources', if the concerned font(.ttf extension) file is not there add it to the list.

Clean your Project and run you should be able to see the font.

Maybe the problem is that the name of font is with space. Remove spaces, in real file name, add it again to your plist and try again with code:

[UIFont fontNamesForFamilyName:@"DKCrayonCrumble"];

This link help you to set font:

set custom font

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM