OStack程序员社区-中国程序员成长平台

标题: ios - iPhone字体问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:07
标题: ios - iPhone字体问题

我的 .ttf 文件无法在我的 iPhone 应用程序中运行。我将此文件添加到我的项目中:

gothamnarrowbook.ttf

我将此添加到我的 plist 中:

<key>UIAppFonts</key>
<array>
    <string>gothamnarrowbook.ttf</string>
</array>

在我的 ViewController 中,我添加了这个:

UIFont *gnb = [UIFont fontWithName"gothamnarrowbook" size:22];

但是 gnb 是零。我做错了什么?



Best Answer-推荐答案


不幸的是,您在 .plist 中引用的字体的实际“名称”不一定与其文件名相同。

要找出字体的真名,在字体册中打开它,你应该可以看到它的真名。也许真正的名字是“Gotham Narrow Book”,或者类似的名字,Font Book 会告诉你。

看看这个blog post了解更多。

还要注意:

Using the name from Font Book works well enough for fonts with one variant, but if your font has multiple variants, and you don't want to get involved with iOS's seemingly incomplete implementation of NSAttributedString, then you'll have to specify the variant explicitly when you load the font.

Using UIFont's class method +fontNamesForFamilyName: you supply the font family name, for example "Cloister Black" which might have two variants "Light" and "Dark", and it will return an NSArray of all variants of that font, "CloisterBlack-Light" and "CloisterBlack-Dark". Notice no spaces.

关于ios - iPhone字体问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8403420/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4