更改字体不起作用
我想将标签的字体从 helvetica 更改为 calibri 粗体。所以我在界面生成器中选择了 calibri 粗体,但在我的 iPhone 上它仍然是 helvetica。当我尝试在代码中更改它时,例如:
[label setFont: [UIFont fontWithName: @"Calibri Bold" size: 48.0]];
label.textColor = [UIColor whiteColor];
我的 iphone 上的字体是 helvetica 12。
错误在哪里?
谢谢 :)
i want to change the font of a label from helvetica to calibri bold. so i chose calibri bold in the interface builder, but on my iphone it's sill helvetica. when i try to change it in the code like:
[label setFont: [UIFont fontWithName: @"Calibri Bold" size: 48.0]];
label.textColor = [UIColor whiteColor];
the font on my iphone is helvetica 12.
where is the mistake?
thank you :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误在于 Calibri Bold 字体不是 iOS 的一部分。
您可以将其作为自定义字体和资源提供。不要忘记将相关键添加到
info.plist
中。它应该是UIAppFonts
,类型数组,包含字体的文件名。然后使用[UIFont familyNames]
获取字体名称 - 它可能与文件名不匹配。The mistake is that the Calibri Bold font is not part of iOS.
You can supply it as a custom font, as a resource. Don't forget to add the relevant keys to the
info.plist
. It should beUIAppFonts
, type array, containing the file names of the fonts. Then get the font name using[UIFont familyNames]
- it may not match the file name.三件事:
1) 并非界面构建器中的所有字体都可以在 iPhone 上使用
2) 您必须选择与字体内部名称完全匹配的名称——这通常不是 IB 字体的“常规”名称。
3)确保您的插座连接正确,否则您的代码将不会更改标签。
但您可以在项目中运行相同的代码来获取最新的名称列表):
下面是 iphone 上内部字体名称的链接:(有点过时了, wordpress.com/2008/10/24/list-of-fonts-available-on-the-iphone/" rel="nofollow">http://ajnaware.wordpress.com/2008/10/24/list-of -iphone 上可用的字体/
Three things:
1) not every font in interface builder is available on the iphone
2) You have to choose the name which matches exactly the internal name for the font -- this is often not the IB "regular" name of the font.
3) make sure your outlets are correctly connected otherwise your code will not change the label.
Here's a link to the internal font names on the iphone: (kind of out of date but you can run his same code in your project to get the up to date list of names):
http://ajnaware.wordpress.com/2008/10/24/list-of-fonts-available-on-the-iphone/
您确定该字体在 iPhone 上可用吗?
这里是一个列表可用字体(可能已经过时,但是......)
Are you sure the font is available on iPhone?
Here is a list of available fonts (maybe out of date, but...)