简体   繁体   中英

What is the correct way to use a custom font in IOS?

I have been trying to use a custom font[1] in my game and I have managed to use it in Android and web but not in IOS.

I have my xcode project like this:

http://discuss.cocos2d-x.org/uploads/default/9079/0e7bfa08016642fa.png

But I have tried writing only Soup of Justice in xcode but that did not work.

In my cocos studio project I have in resource.js:

font: 'res/Fonts/Soup of Justice.ttf' and it's preloaded in the main.js

Then my calls of cc.LabelTTF : var label = new cc.LabelTTF("Prueba" , "Soup of Justice", 50); but i have also tried var label = new cc.LabelTTF("Prueba" , 'res/Fonts/Soup of Justice.ttf', 50);

Any help would be welcome!

[1] http://www.dafont.com/es/soup-of-justice.font

Hello have you checked the fonts in your app like this?

NSArray *fontFamilies = [UIFont familyNames];

for (int i = 0; i < [fontFamilies count]; i++)
{
    NSString *fontFamily = [fontFamilies objectAtIndex:i];
    NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
    NSLog (@"%@: %@", fontFamily, fontNames);
}

This small construct will list all the fonts that can be used in your app along with the fonts added in project by you, the name displayed there would the name of font which can be used

This is the link that should help you, and get you on roll...

  1. Add the font to your project
  2. Include the names of the fonts in your PList under key under key "Fonts provided by application"
  3. Use the Fonts with correct name.

Use the code written below to print all the fonts and search for the one you want to use.

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

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

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