Has anyone had success using custom otf fonts on the iPhone?

后端 未结 6 642
粉色の甜心
粉色の甜心 2020-12-23 11:45

It looks like there a few working solutions for using custom true type fonts (ttf) on the iPhone, most notably Can I embed a custom font in an iPhone application? However,

6条回答
  •  悲哀的现实
    2020-12-23 12:24

    I had trouble with this, too. Here is what worked for me:

    1. Copy the font files into the Resources.
    2. Check to see that the font files are in 'Build Phases'->'Copy Bundle Resources' (Xcode put them there for me when I added the files to the Resources. If, for some reason, they are not there, add them.
    3. Add the filenames to your info.plist file as describe above. Include the extensions.
    4. Open Font Book, select your font and Preview-Show Font Info and look at the 'Family', e.g., 'Foo'
    5. Put this in your code somewhere and set a breakpoint to check the array of names: NSArray *names = [UIFont fontNamesForFamilyName:@"Foo";
    6. Run your app and when it breaks, right-click on the 'names' variable in the debugger. This will show you the font names to use, e.g.: <__NSCFArray 0xe9c4da0>( Foo-100Italic, Foo-100 )
      Note that my font names were not shown correctly anywhere else, not in the filename nor in Font Book.
    7. You should be good to go with:
      myLabel.font = [UIFont fontWithName:@"Foo-100Italic" size:24];

提交回复
热议问题