UIFont fontWithName返回nil [英] UIFont fontWithName returns nil

查看:611
本文介绍了UIFont fontWithName返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的info.plist中,我添加了一个键应用程序提供的字体,并添加了 EdwardianScriptITCStd.otf

  NSLog(@%@,[UIFont fontWithName:@EdwardianScriptITCStd
size:16.0f]) ;

我使用 [UIFont familyNames]打印字体系列它不是那里:

 
Thonburi,
Snell Roundhand $ bAcademy Engraved LET,
Marker Felt,
Geeza Pro,
Arial Rounded MT Bold,
Trebuchet MS,
Arial,
Marion,
Gurmukhi MN,
Malayalam Sangam MN,
Bradley Hand,
Kannada Sangam MN,
Bodoni 72 Oldstyle,
Cochin,
Sinhala Sangam MN,
Hiragino Kaku Gothic ProN,
Papyrus,
Verdana,
Zapf Dingbats,
Courier,
Hoefler Text,
Euphemia UCAS,
Helvetica,
Hiragino Mincho ProN,
Bodoni Ornaments,
Apple Color Emoji,
Optima,
Gujarati Sangam MN,
Devanagari Sangam MN,
Times New Roman,
Kailasa,
Telugu Sangam MN,
Heiti SC,
Apple SD哥特式Neo,
Futura,
Bodoni 72
Baskerville,
Chalkboard SE,
Heiti TC,
Copperplate,
Party LET,
American Typewriter,
Bangla Sangam MN,
Noteworthy,
Zapfino,
Tamil Sangam MN,
DB LCD Temp,
Arial Hebrew b $ b Chalkduster,
格鲁吉亚,
Helvetica Neue,
Gill Sans,
Palatino,
Courier New,
Sangam MN,
Didot,
Bodoni 72 Smallcaps

我错过了什么?
感谢!

解决方案

我的意见开始变长,所以我决定提交一个答案: )


  1. 自定义字体仅在iOS 3.2及更高版本中受支持,因此请确保您的部署目标构建设置不会返回

  2. 验证字体是否包含在构建目标中(在复制捆绑资源构建阶段)

    / li>
  3. 检查应用程序提供的字体键的原始值,以确保它是正确的。在Xcode中查看* .plist时,右键单击并选择显示原始键/值,然后验证键是 UIAppFonts


  4. 我相信当使用 fontWithName:size:时,iOS需要一个字体的PostScript名称,您可以通过打开字体在Apple's Font Book中输入命令+ I


  5. 使用自定义字体和 UILabel 。我不知道这个问题是否仍然存在。




p>如果仍然无法运行,请此堆栈



编辑

不能保证我有与您相同的字体文件,但在我的机器上PostScript名称是EdwardianScriptITC


In my info.plist, I added a key "Fonts provided by application" and added EdwardianScriptITCStd.otf

But, when I try to get that font, it returns nil:

NSLog(@"%@", [UIFont fontWithName:@"EdwardianScriptITCStd" 
                                size:16.0f]);

I printed the font families using [UIFont familyNames] and it's not there either:

(
    Thonburi,
    "Snell Roundhand",
    "Academy Engraved LET",
    "Marker Felt",
    "Geeza Pro",
    "Arial Rounded MT Bold",
    "Trebuchet MS",
    Arial,
    Marion,
    "Gurmukhi MN",
    "Malayalam Sangam MN",
    "Bradley Hand",
    "Kannada Sangam MN",
    "Bodoni 72 Oldstyle",
    Cochin,
    "Sinhala Sangam MN",
    "Hiragino Kaku Gothic ProN",
    Papyrus,
    Verdana,
    "Zapf Dingbats",
    Courier,
    "Hoefler Text",
    "Euphemia UCAS",
    Helvetica,
    "Hiragino Mincho ProN",
    "Bodoni Ornaments",
    "Apple Color Emoji",
    Optima,
    "Gujarati Sangam MN",
    "Devanagari Sangam MN",
    "Times New Roman",
    Kailasa,
    "Telugu Sangam MN",
    "Heiti SC",
    "Apple SD Gothic Neo",
    Futura,
    "Bodoni 72",
    Baskerville,
    "Chalkboard SE",
    "Heiti TC",
    Copperplate,
    "Party LET",
    "American Typewriter",
    "Bangla Sangam MN",
    Noteworthy,
    Zapfino,
    "Tamil Sangam MN",
    "DB LCD Temp",
    "Arial Hebrew",
    Chalkduster,
    Georgia,
    "Helvetica Neue",
    "Gill Sans",
    Palatino,
    "Courier New",
    "Oriya Sangam MN",
    Didot,
    "Bodoni 72 Smallcaps"
)

What am I missing? Thanks!

解决方案

My comments were starting to get lengthy, so I've decided to submit an answer instead :)

  1. Custom fonts are only supported in iOS 3.2 and above, so make sure your Deployment Target build setting doesn't go back any farther than version 3.2.

  2. Verify that the font is included in your build target (in the "Copy Bundle Resources" build phase)

  3. Check the raw value of the key for "Fonts provided by application" to make sure it's correct. When viewing the *.plist in Xcode, right-click and choose "Show Raw Keys/Values", then verify the key is UIAppFonts.

  4. I believe iOS requires the PostScript name for a font when using fontWithName: size:, which you can find/verify by opening the font in Apple's Font Book and typing command+I.

  5. At one point, there was an issue with using custom fonts and UILabel. I am not sure if this problem still exists. The solution was to subclass UILabel and set the font therein.

If it still doesn't work, this Stack Overflow thread on custom fonts has quite a bit of info, you may have some luck there.

EDIT
There's no guarantee that I have the same font file as you, but on my machine the PostScript name is "EdwardianScriptITC"

这篇关于UIFont fontWithName返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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