IOS中的自定义字体未在设备上反映

我按照本教程 ,自定义字体显示在我的故事板上,但当我执行我的应用程序(在模拟器或设备上)时,字体没有反映出来。 有谁可以帮忙。 这就是我做的:

1- downloaded a .ttf file and copied it to my project 2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font. 3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was shown on the storyboard correctly. 

我错过了什么吗?

谢谢@Andrey Chernuka和@jcaron。 我通过将目标成员资格设置为我的项目然后退出项目(由于某种原因清理无效)并重新打开项目并设置了所有内容来解决问题。 当我打印print (UIFont.familyNames())时出现字体名称

您是否仅将.ttf文件夹添加到支持文件中。 然后像这样编辑info.Plist

Application提供的字体作为数组

项目0为Heiti SC.ttf

现在你可以设置label.font = [UIFont fontWithName:@"Heiti SC" size:15];

然后,您还需要添加ttf文件以在目标构建阶段复制捆绑资源。

您只需按照以下步骤操作。

第1步 – 下载.ttf文件并将其复制到我的项目第2步 – 在info.plist中添加了“由应用程序提供的字体”,并添加了一行,其名称为我的自定义字体。

在此处输入图像描述

第3步 – 显示添加的字体是否存在于项目中。 将过去复制到application:didFinishLaunchingWithOptions

 NSLog(@"Available fonts: %@", [UIFont familyNames]); NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]]; NSArray *fontNames; NSInteger indFamily, indFont; for (indFamily=0; indFamily<[familyNames count]; ++indFamily) { NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]); fontNames = [[NSArray alloc] initWithArray: [UIFont fontNamesForFamilyName: [familyNames objectAtIndex:indFamily]]]; for (indFont=0; indFont<[fontNames count]; ++indFont) { NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]); } } 

第4步 - 找到你的字体和同名的名字检查故事板。

这绝对有效。