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

查看:11
本文介绍了如何检查字体是否在 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:

这是一个使用 [UIFont familyName] 的示例:

Here's an example of using [UIFont familyName]:

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

这将产生一个像这样的列表:

This will produce a list like this:

字体系列:(吞武里,斯内尔圆手",学院刻 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"]);

这将产生一个像这样的列表:

That will produce a list like this:

Courier 新系列字体:(快递新PSMT,"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 类方法 familyNamesfontNamesForFamilyName:.

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

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

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