【问题标题】:Custom Font in IOS Not Reflected On DeviceIOS 中的自定义字体未反映在设备上
【发布时间】:2016-03-13 07:22:25
【问题描述】:

我关注了这个tutorial,自定义字体显示在我的故事板上,但是当我执行我的应用程序(在模拟器或设备上)时,字体没有反映。谁能帮忙。 这就是我所做的:

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.

我错过了什么吗?

【问题讨论】:

  • 确保字体文件包含在您的目标中:单击它,然后转到文件检查器(窗口右侧面板中的第一个选项卡)并检查旁边是否有复选标记您在“目标会员”部分中的目标。
  • 还要检查您是否在 Info.plist 中列出了文件名,而不是字体名。
  • 如果你做 NSLog(@"%@", [UIFont familyNames]); 怎么办?您的字体系列名称是否显示在列表中?
  • 复选标记没有被选中,所以我选择了它。这可能是因为我使用多种语言。打印 NSLog 时,我看不到字体名称
  • 选中复选标记后,请执行 Clean,然后再次运行应用程序,看看它是否现在打印 familyName(不是字体名称!)

标签: ios iphone fonts swift2.1


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    Application提供的字体作为数组

    第 0 项为 Heiti SC.ttf

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

    那么你还需要在目标构建阶段添加ttf文件来复制bundle资源。

    【讨论】:

    • "那么你还需要在目标构建阶段添加ttf文件来复制bundle资源。" --> 这对我有用!!
    【解决方案3】:

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

    第 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 步 - 找到您的字体名称并在情节提要中找到相同的名称。

    这绝对有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 2013-03-31
      • 1970-01-01
      • 2012-11-16
      • 2011-12-26
      • 2013-03-26
      • 2015-04-01
      相关资源
      最近更新 更多