视网膜显示器上的字体问题

时间:2014-07-02 14:01:03

标签: ios uitextfield uicolor uifont drawinrect

我是Objective-C的新手,我需要一些帮助 我的问题是我有一个UITextField的子类,我想将占位符字体设置为使用此代码自定义

- (void)drawPlaceholderInRect:(CGRect)rect {
[[self placeholder] drawInRect:rect withAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Georgia Belle" size:25],NSForegroundColorAttributeName:RGBA(174, 150, 108, 1)}]; } 

我有下一个问题。 当我在模拟器中选择iPad并编译程序时,一切都按预期进行,但当我选择视网膜设备时,我会得到下一个例外:

 [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0].

我要问的是:为什么它适用于非视网膜,但会引起视网膜上的异常,任何类型的视网膜设备。

2 个答案:

答案 0 :(得分:2)

您的问题与您的字体有关。

HelveticaNeueInterface-Regular是系统字体。喜欢:[UIFont systemFontOfSize:25]

另一方面,我无法使用RGBA(174, 150, 108, 1)我的代码中出现了问题。

您应该确保您的项目中导入了名为" Georgia Belle" 的字体。

Georgia Belle.ttf 拖放到您的项目中

enter image description here

打开Info.plist并添加一个新行:

enter image description here

打开目标/构建阶段/复制捆绑资源
Xcode在这里失败了,有时它没有添加我们的新字体:

enter image description here

点击+

enter image description here

完成

enter image description here

问题解决了。

enter image description here enter image description here

你可以download my solution from GitHub

最后一件事。这是一个很好的网站,包含所有标准的ios字体:http://iosfonts.com

答案 1 :(得分:1)

您必须将字体添加到复制包资源