如何从otf或ttf文件中获取字体名称? [英] How do I get the font name from an otf or ttf file?

查看:1251
本文介绍了如何从otf或ttf文件中获取字体名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在之前的应用程序中使用了自定义字体。

I have used a custom font in my previous app.

文件名为ProximaNova-Regular.otf并加载我刚使用的字体。 。

The file name was "ProximaNova-Regular.otf" and to load the font I just used...

[UIFont fontWithName:@"ProximaNova-Regular" size:20];

这完美无缺。

现在进入这个新应用程序我有三个字体文件...

Now in this new app I have three font files...

Dude_Willie.otf
Impact
handsean.ttf

但我不确定如何加载这些。

But I'm not sure how to load these.

我试过了

[UIFont fontWithName:<the file name> size:20];

但这只是回到使用Helvetica。

But this just falls back to using Helvetica.

如何找到要使用的名称?

How can I find what name to use?

推荐答案

按照以下四个简单步骤添加和使用新字体您的iOS应用:

Follow these four easy steps to add and use a new font in your iOS app:


  • your_new_font.ttf your_new_font.otf 添加到您的Xcode项目

  • 在项目的info.plist中,为 your_new_font.ttf your_new_font.otf 添加一个新条目到 UIAppFonts 数组(这个的纯文本是'应用程序提供的字体')

  • 此时,我建议添加这个临时的调试块用于转储应用程序可访问的所有字体的代码,包括新添加的your_new_font:

  • Add your_new_font.ttf or your_new_font.otf to your Xcode project
  • In your project's info.plist, add a new entry for your_new_font.ttf or your_new_font.otf to the UIAppFonts array (plain text for this one is 'Fonts provided by application')
  • At this point, I recommend adding this temporary chunk of debug code to dump all fonts that are accessible by your app, including your newly added your_new_font:

for(NSString *fontfamilyname in [UIFont familyNames])
{
    NSLog(@"family:'%@'",fontfamilyname);
    for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
    {
        NSLog(@"\tfont:'%@'",fontName);
    }
    NSLog(@"-------------");
}





  • In调试输出,查找新字体的'family'和'font'名称。将显示为与新字体系列对应的字体名称(可能有多个与您的新字体系列相关联的字体)传递给 UIFont * myNewFont = [UIFont fontWithName: @font_name_from_debug_output大小:20] ,你应该开展业务!

    • In the debug output, look for your new font's 'family' and 'font' name. Pass whatever is displayed as the 'font' name corresponding to your new font family (there could be more than one 'font' associated with your new font 'family') to UIFont *myNewFont = [UIFont fontWithName:@"font_name_from_debug_output" size:20] and you should be in business!
    • 这篇关于如何从otf或ttf文件中获取字体名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆