如何检查iOS版本中是否有字体? [英] How to check if a font is available in version of iOS?

查看:253
本文介绍了如何检查iOS版本中是否有字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款使用ChalkboardSE-Regular字体的应用,我的部署目标是4.0+。此字体在4.1中不可用,但在4.3中受支持。检查字体是否存在的最佳方法是什么,如果不存在,请在< 4.1版本的iOS上使用其他支持的字体。 [UIFont familyName]返回这些字体的列表Chalkboard SE

I'm currently working on an app that uses the "ChalkboardSE-Regular" font and my deployment target is 4.0+. This font was not available in 4.1 but it is supported in 4.3. What would be the best way to go about checking if the font exists and if it does not, use another supported font on the <4.1 versions of iOS. [UIFont familyName] returns a list of these fonts "Chalkboard SE"

提前致谢!

T

推荐答案

[UIFont familyName] 支持回iPhone OS 2.0(之前2.0,iPhone或iPod touch上不允许使用第三方应用程序),所以我会用它来检查当前设备上是否存在字体系列,如果它不存在,请使用合适的后备字体对于那个版本的iOS。这是John Gruber在2007年从原始iPhone获得的iPhone字体列表(与当天的Mac OS X中的字体形成对比)。我没有检查过它们,但我检查的iOS字体仍在iOS 5中:

[UIFont familyName] is supported back to iPhone OS 2.0 (before 2.0, third-party apps were not allowed on iPhone or iPod touch) , so I would use that to check to see if a font family exists on the current device, and if it doesn't exist, use a suitable fall-back font for that version of iOS. Here's John Gruber's list of iPhone fonts from the original iPhone in 2007 (contrasted with the fonts in Mac OS X of the day). I haven't checked them all, but the iOS fonts I did check are still in iOS 5:

  • http://daringfireball.net/misc/2007/07/iphone-osx-fonts

以下是使用 [UIFont familyName]

NSLog (@"Font families: %@", [UIFont familyNames]);

这将生成如下列表:

字体系列:(
Thonburi,
Snell Roundhand,
Academy Engraved LET,等等。

Font families: ( Thonburi, "Snell Roundhand", "Academy Engraved LET", ... et cetera.

一旦知道姓氏,就可以使用 UIFont 类方法 fontNamesForFamilyName 获取NSArray中所有字体的名称。例如:

Once you know the family name, you can use the UIFont class method fontNamesForFamilyName to get an NSArray of the names of all the fonts in the family. For example:

NSLog (@"Courier New family fonts: %@", [UIFont fontNamesForFamilyName:@"Courier New"]);

这将生成如下列表:


Courier新系列字体:(
CourierNewPSMT,
CourierNewPS-BoldMT,
CourierNewPS-BoldItalicMT,
CourierNewPS-ItalicMT

Courier New family fonts: ( CourierNewPSMT, "CourierNewPS-BoldMT", "CourierNewPS-BoldItalicMT", "CourierNewPS-ItalicMT" )

以下示例代码打印当前设备上每个系列中每种字体的列表:

The following example code prints a list of each font in every family on the current device:

NSArray *fontFamilies = [UIFont familyNames];

for (int i = 0; i < [fontFamilies count]; i++)
{
    NSString *fontFamily = [fontFamilies objectAtIndex:i];
    NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
    NSLog (@"%@: %@", fontFamily, fontNames);
}

有关更多信息,请查看iOS开发人员参考文档中的 UIFont 类方法 familyNames fontNamesForFamilyName:

For more information, check out the iOS Developer Reference document for the UIFont class methods familyNames and fontNamesForFamilyName:.

这篇关于如何检查iOS版本中是否有字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆