如何检查字体是否在 iOS 版本中可用?

How to check if a font is available in version of iOS?(如何检查字体是否在 iOS 版本中可用?)
本文介绍了如何检查字体是否在 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字体

这是一个使用 [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 类方法 familyNames 和 fontNamesForFamilyName:.

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)