如何在ios中启用osf(旧式数字)?

时间:2014-09-23 08:40:42

标签: ios objective-c xcode

所以我的问题是我有字体女巫支持osf(旧式数字)但我不知道如何用UIFont启用它?

1 个答案:

答案 0 :(得分:2)

我已经弄清楚了。

OSF是某些字体中包含的可选功能,因此我们需要使用

激活此功能
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{
                                                                                            UIFontDescriptorNameAttribute : @"MyriadPro-Light",
                                                                                            UIFontDescriptorFeatureSettingsAttribute : @[osfFontFeature]
                                                                                            }];

osfFontFeature是

NSDictionary *osfFontFeature = @{
                                     UIFontFeatureTypeIdentifierKey : @(21),
                                     UIFontFeatureSelectorIdentifierKey : @(0)
                                     };

可在此处获取要素类型和选择标识符键: https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html#Type21

最后,我们使用

创建字体
[UIFont fontWithDescriptor:fontDescriptor size:17.0]