关于ios:斜体字体不适用于XCode

Italic Font Is Not Working on XCode

我已将我的ttf字体(ABeeZee-Italic.ttf)从Google WebFonts复制到Supporting Files中并添加到plist中:

enter image description here

并为我的Label分配标签= 4:

enter image description here

因为我有以下代码将字体嵌入到UILabel中:

1
2
3
4
5
6
7
8
9
10
11
for (UILabel *customLabel in [[self view] subviews]) {
    if (customLabel.tag == 1) {
        [customLabel setFont:[UIFont fontWithName:@"Raleway-ExtraLight" size:21]];
    } else if (customLabel.tag==2){
        [customLabel setFont:[UIFont fontWithName:@"ABeeZee-Regular" size:14]];
    } else if (customLabel.tag==3){
        [customLabel setFont:[UIFont fontWithName:@"ABeeZee-Regular" size:11]];
    } else if (customLabel.tag==4){
        [customLabel setFont:[UIFont fontWithName:@"ABeeZee-Italic" size:12]];
    }
}

一切都像灵符一样工作,但斜体字体未加载到我的iPod(iOS 6.1.3)中。 带有标签4的UILabel是iOS系统字体。 不是ABeeZee-Italic。

我试图更改标签号,但也失败了。 对于将非常规字体嵌入到iOS中有什么特殊要求?

谢谢

UPDATE @iPatel答案:这是我的FontBook的样子,它具有相同的名称...
enter image description here


您可以通过两种方式执行此操作。

使用ttf文件

1
[customLabel setFont:[UIFont fontWithName:@"Raleway-ExtraLight.ttf" size:21]];

要么

使用字体名称

1
[customLabel setFont:[UIFont fontWithName:<Name of Raleway-ExtraLight> size:21]];

在您的情况下,只需在setFont:中添加.ttf,否则获取字体名称,如下图所示。

只需右键单击.ttf文件>获取信息>全名(您的字体名称。您可以在setFont中将此名称用作字体名称)

enter image description here

编辑

在此处检查全名并将其粘贴到您的代码中。

1
[customLabel setFont:[UIFont fontWithName:@"ABeeZee Italic" size:21]];

编辑1

可能是您需要注册字体。只需尝试注册并检查。


检查" FontBook"中字体的真实名称(ABeeZee-Italic)吗?并在" FontBook"中输入字体名称。

并使用像

1
[myLabelName  setFont: [UIFont fontWithName:@"Font Name From Font Book" size:32]];

有关如何在应用程序中添加自定义字体的更多信息。然后阅读此答案。

编辑:

也可以尝试

  • 从项目中选择您的字体
  • 右键点击
  • 使用外部编辑器打开
  • 安装字体
  • 选择插入的字体
  • 并检查什么是"全名",然后将其复制并粘贴到您的代码中:

可能会有帮助:)