Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 无法在UIButton中使用自定义字体_Iphone_Ios_Uibutton_Uifont - Fatal编程技术网

Iphone 无法在UIButton中使用自定义字体

Iphone 无法在UIButton中使用自定义字体,iphone,ios,uibutton,uifont,Iphone,Ios,Uibutton,Uifont,我正在尝试在我的应用程序中使用自定义字体,它是ttf格式的。在项目设置中,我添加了如下字体名称 我在我的参考资料文件夹中添加了这种字体,如下所示 我尝试使用的字体是这个 _enterButton.titleLabel.font = [UIFont fontWithName:@"Venus Rising" size:45.0]; 如果我使用Arial或其他字体,效果很好。但当我尝试使用这种字体时,它根本不起作用。谁能告诉我为什么 UILabel *label1 = [[UILabel al

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

我在我的参考资料文件夹中添加了这种字体,如下所示

我尝试使用的字体是这个

_enterButton.titleLabel.font =  [UIFont fontWithName:@"Venus Rising" size:45.0];
如果我使用Arial或其他字体,效果很好。但当我尝试使用这种字体时,它根本不起作用。谁能告诉我为什么

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];
请试试这个


这可能对您有所帮助

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

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

尝试此循环检查应用程序中的所有可用字体:

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

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

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


另外,不要忘记在应用程序的Info.plist中,在“Fonts Providered by application”键下添加名称。希望有帮助!:)

我以前试过很多次,有没有分机。在看到你的回复后,我想知道它将如何解决,我想做最后一次尝试。是的,成功了。谢谢你,伙计!!您提供的链接看起来很酷。我以前解决过这个问题。但无论如何,非常感谢你们,这是一个很好的博客,我读到tat topicThis并没有解决他的问题,他不想使用“Grinched”或“Energon”字体。他的问题是字体的实际名称。但是字体的问题不起作用。这里是如何将外部字体安装到我们的项目中的教程。这很有帮助,但是我认为右键单击字体并获取信息更容易-您可以在那里找到实际名称。:)如果字体样式只有常规字体,我们不能将其设为粗体吗??我正在尝试为按钮添加标题。我使用的字体如上所述。它只有不可能的常规类型。如果字体没有加粗版本,则不能仅使用常规字体将其加粗。