简体   繁体   English

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

[英]Font problems on retina display

I'm kind of newbie in Objective-C and I need some help My problem is that I have a subclass of UITextField , and I want to set the placeholder font to be custom with this code 我是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)}]; } 

and I have the next issue. 我有下一个问题。 When I select iPad in the simulator, and I compile the program, everything goes as it should, but when I select a retina device I get the next Exception: 当我在模拟器中选择iPad并编译程序时,一切都按预期进行,但是当我选择一个视网膜设备时,我会得到下一个异常:

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

What I'm asking is: why it works on non-retina but throws exceptions on retina, any kind of retina device. 我要问的是:为什么它适用于非视网膜,但会引起视网膜上的异常,任何类型的视网膜设备。

Your problem is with your Font. 你的问题是你的字体。

HelveticaNeueInterface-Regular is the System font. HelveticaNeueInterface-Regular是系统字体。 Like: [UIFont systemFontOfSize:25] 喜欢: [UIFont systemFontOfSize:25]

In the other hand I can't use RGBA(174, 150, 108, 1) I've got an issue in my code. 在另一方面,我不能使用RGBA(174, 150, 108, 1)我的代码中有一个问题。

You should be sure that you have the font named "Georgia Belle" is in your project well imported. 您应该确保在项目中导入了名为“Georgia Belle”的字体。

Drag and drop Georgia Belle.ttf to your project Georgia Belle.ttf拖放到您的项目中

在此输入图像描述

Open Info.plist and add a new line: 打开Info.plist并添加一个新行:

在此输入图像描述

Open your Target / Build Phases / Copy Bundle Resources 打开目标/构建阶段/复制捆绑资源
Xcode fails here and sometimes its not adding our new font: Xcode在这里失败,有时它不添加我们的新字体:

在此输入图像描述

Click + 点击+

在此输入图像描述

Done 完成

在此输入图像描述

Problem solved. 问题解决了。

在此输入图像描述在此输入图像描述

You can download my solution from GitHub 您可以从GitHub下载我的解决方案

One last thing. 最后一件事。 This is a nice website with all the standard ios fonts: http://iosfonts.com 这是一个很好的网站,包含所有标准的ios字体: http//iosfonts.com

您必须将字体添加到副本包资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM