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

IOS中的自定义字体未反映在设备上,ios,iphone,fonts,swift2.1,Ios,Iphone,Fonts,Swift2.1,我遵循这一点,自定义字体显示在我的故事板上,但当我执行我的应用程序(在模拟器或设备上)时,字体没有反映出来。有人能帮忙吗。 这就是我所做的: 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 storyboar

我遵循这一点,自定义字体显示在我的故事板上,但当我执行我的应用程序(在模拟器或设备上)时,字体没有反映出来。有人能帮忙吗。 这就是我所做的:

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.

我错过什么了吗

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

应用程序提供的字体采用数组形式

项目0作为Heiti SC.ttf

现在您可以设置
label.font=[UIFont fontWithName:@“Heiti SC”大小:15]


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

您只需按照以下步骤操作即可

步骤1-下载一个.ttf文件并将其复制到我的项目中 步骤2-在info.plist中添加“应用程序提供的字体”,并添加一行,其中包含我的自定义字体名称

步骤3-显示添加的字体是否存在于项目中。将过去复制到
应用程序:使用选项完成启动

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]);
        }

    }
NSLog(@“可用字体:%@,[UIFont familyNames]);
NSArray*familyNames=[[NSArray alloc]initWithArray:[UIFont familyNames]];
NSArray*fontNames;
NSInteger indFamily,indFont;

对于(indFamily=0;indFamily谢谢@Andrey Chernuka和@jcaron。我通过将目标成员身份设置为我的项目,然后退出该项目(由于某些原因,清理不起作用),然后重新打开该项目,并设置了所有内容。打印
print(UIFont.familyNames())时,字体名称出现在屏幕上

确保目标中包含字体文件:单击该文件,然后转到文件检查器(窗口右侧面板的第一个选项卡),并检查“目标成员资格”中目标旁边是否有复选标记部分。还要检查您是否在Info.plist中列出了文件名,而不是字体名。如果您执行NSLog(@“%@,[UIFont familyNames]);?您的字体系列名称是否显示在列表中?未选中复选标记,因此我选择了它。这可能是因为我使用多种语言。打印NSLog时,我看不到字体名称选中复选标记后,请执行清理,然后再次运行应用程序,查看是否立即打印familyName(不是字体名称!)“然后,您还需要添加ttf文件,以便在目标构建阶段复制捆绑包资源。”-->!!