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

后端 未结 6 570
粉色の甜心
粉色の甜心 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:17

    I researched this throughly, and this is the best method I found:

    1) Convert font file to TTF using this online tool: http://www.freefontconverter.com/

    2) Add the TTF files to your project

    3) Make some configurations to your info.plist file:

    3.1) Edit info.plist as source code (right click on file -> open as -> source code)

    3.2) Add this:

     <key>UIAppFonts</key>
     <array>
      <string>font1.ttf</string>
      <string>font2.ttf</string>
      ...etc...
     </array>
    

    3.3) Your info.plist should have this now:

    info plist should look like this now

    4) Use the new fonts just like the system fonts:

    [UIFont fontWithName:@"font1" size:16.0];

    (Notice no ".ttf" in the font name)

    0 讨论(0)
  • 2020-12-23 12:18

    For my own project I wanted to use the opentype font and I basically used this method:

    Add your custom font file into your project using XCode as a resource Add a key to your info.plist file (Fonts provided by application) For each font you have, enter the full name of your font file (including the extension) save info.plist then use this for your labels (ex:)

    UIFont* font = [UIFont fontWithName:@"Harrowprint" size:20];
    

    In my case @"Harrowprint" was the filename without the extension and not the font name provided by Finder.

    My font was an otf and it worked...so I guess it's supported...or I was lucky. I'll test another font..and keep you posted..

    references:

    • http://blog.beefyapps.com/2010/06/custom-fonts-in-ios-4/
    • Can I embed a custom font in an iPhone application?
    0 讨论(0)
  • 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];
    0 讨论(0)
  • 2020-12-23 12:28

    This article answers your question (it worked like a charm for me using OTF): http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

    OTF is perfectly supported, no need to convert to TTF

    0 讨论(0)
  • 2020-12-23 12:33

    With regards to the first answer - the solution is correct (i.e. just convert the font over to TTF) but the software suggested is a super hassle to compile and install. Instead I just did a quick google search and used this instead: http://www.freefontconverter.com/ and that worked perfectly.

    (Make sure to add the font to your info.plist file as well)

    0 讨论(0)
  • 2020-12-23 12:40

    Must you use an otf font on the device or can you convert it to ttf? It is relatively straightforward to convert an OTF font to a TTF font using a tool such as fontforge, perhaps that would be an easy solution.

    0 讨论(0)
提交回复
热议问题