带有自定义字体的UIFont因Nil而失败 [英] UIFont with custom font fails with Nil

查看:126
本文介绍了带有自定义字体的UIFont因Nil而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Xcode 4.2中为我的项目添加自定义字体,但每当我尝试使用它时,我都会收到一个错误,该对象为零。

I'm trying to add a custom font to my project in Xcode 4.2, but whenever I try to use it, I get a error that the object is nil.

我已经完成了以下操作:

1)在我的.plist'字体中添加了一行由应用程序'值提供:LCDMono2 Ultra.ttf


2)添加了字体到我的支持文件并在XCode中显示它以验证它已被添加。

3)使用获取信息验证全名是LCDMono2 Ultra

4)创建字体我的项目:

I have done the following:
1) Added a row to my .plist 'Fonts provided by application' value: "LCDMono2 Ultra.ttf"
2) Added the font to my Supporting Files and showed it in XCode to verify it was added.
3) Verified using Get Info that the Full Name is "LCDMono2 Ultra"
4) Created the font in my project with:

UIFont *myFont = [UIFont fontWithName:@"LCDMono2 Ultra" size:16];

我试过这个变种:

UIFont *myFont = [UIFont fontWithName:@"LCDMono2 Ultra" size:16.f];

5)尝试使用字体名称(addObject:myFont.fontName) ,生成'nil'错误。

5) Tried to use the font name (addObject:myFont.fontName), generating the 'nil' error.

可能导致错误的原因是什么?它可能是名称中的空格吗?

What could be causing the error? Could it be something like the space in the name?

推荐答案

添加后,字体全名中的空格被自动删除它到项目。我检查了原始的字体文件,空间就在那里,所以Apple一定不想处理空格。我将引用更改为LCDMono2Ultra并且它可以正常工作。

The space in the Full Name of the font was removed automatically after adding it to the project. I've checked the original font file, and the space is there, so Apple must not want to deal with spaces. I changed the reference to "LCDMono2Ultra" and it works.

这篇关于带有自定义字体的UIFont因Nil而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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