3

我正在尝试在我的应用程序中使用自定义字体,它是 ttf 格式。在项目设置中,我添加了如下字体名称。

在此处输入图像描述

我已经在我的资源文件夹中添加了该字体,如下所示

在此处输入图像描述

我尝试使用的字体就是这个在此处输入图像描述

_enterButton.titleLabel.font =  [UIFont fontWithName:@"Venus Rising" size:45.0];

如果我使用 Arial 或其他字体,它可以正常工作。但是当我尝试使用这种字体时,它根本不起作用。谁能告诉我为什么??

4

4 回答 4

4

我下载了字体,因为我认为它的名称与文件名不同。看看这张图片。

在此处输入图像描述

也不要忘记将名称添加到应用程序的 Info.plist 中,在“应用程序提供的字体”键下。希望能帮助到你!:)

于 2012-07-17T09:27:26.150 回答
2

您错过了 info.plist 中的字体扩展,我的意思是在 Info.plist 中,“应用程序提供的字体”您需要设置“Venus Rising.ttf”然后您的问题将得到解决

于 2012-07-17T09:18:23.087 回答
1

几天前我遇到了同样的问题。对我来说,字体名称与 ttf 文件名不同。

试试这个循环来检查你的应用程序中所有可用的字体:

for (id familyName in [UIFont familyNames]) {
    NSLog(@"family name : %@",familyName);
    for (id font in [UIFont fontNamesForFamilyName:familyName]) {
        NSLog(@"    %@",font);
    }
}

在您的情况下,Venus Rising 应该显示为姓氏,但您应该在代码中使用的字体的确切名称可能是 VenusRisingRegular 或类似的名称。

于 2012-07-17T09:18:23.650 回答
0
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 240, 40)];
[label1 setFont: [UIFont fontWithName: @"Grinched" size:24]];
[label1 setText:@"Grinched Font"];
[[self view] addSubview:label1];

UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 240, 40)];
[label2 setFont: [UIFont fontWithName: @"Energon" size:18]];
[label2 setText:@"Energon Font"];
[[self view] addSubview:label2];

请试试这个。

它可能对你有帮助

于 2012-07-17T09:17:58.953 回答