将自定义字体添加到 iOS 应用程序以查找其真实姓名 [英] Adding custom fonts to iOS app finding their real names
问题描述
我有两种字体要添加到我的应用中以供使用.
I have two fonts to add in my app for using.
这是字体图片.目前文件被命名为
Here is the font images. Currently the files are named as
name.font = [UIFont fontWithName:@"Helvetica Neue LT Pro-Medium" size:10];
headline.font = [UIFont fontWithName:@"Helvetica Neue LT Pro-Light" size:8];
在plist文件中的Font Avaliable选项
中放置相同的名称.
putting same name in the Font Avaliable option in plist file
.
我也试过添加像
HelveticaNeueLTPro-Lt
HelveticaNeueLTPro-Md
但似乎没有任何效果.我如何获得字体的确切名称.
but nothing seems to work. How can i get the exact name of the fonts.
推荐答案
使用 +[UIFont familyNames]
列出系统已知的所有字体系列名称.对于每个系列名称,您可以使用 +[UIFont fontNamesForFamilyName:]
列出系统已知的所有字体名称.尝试将它们打印出来以查看系统期望的名称.示例代码:
Use +[UIFont familyNames]
to list all of the font family names known to the system. For each family name, you can then use +[UIFont fontNamesForFamilyName:]
to list all of the font names known to the system. Try printing those out to see what name the system expects. Example code:
static void dumpAllFonts() {
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"%@", fontName);
}
}
}
将其放入您的应用中,调用它,然后看看您会得到什么.如果您在输出中看到适合您字体的名称,请使用它.否则,可能您没有将字体正确添加到您的应用中.
Put that in your app, call it, and see what you get. If you see a name in the output that looks appropriate for your font, use it. Otherwise, perhaps you haven't properly added the font to your app.
在 Swift 中:
func dumpAllFonts() {
for familyName in UIFont.familyNames {
for fontName in UIFont.fontNames(forFamilyName: familyName) {
print(fontName)
}
}
}
这篇关于将自定义字体添加到 iOS 应用程序以查找其真实姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!