这些被称为小写数字,可以使用UIFontDescriptor打开。
首先,你需要为一些常量导入CoreText:
#import <CoreText/SFNTLayoutTypes.h>
or
@import CoreText.SFNTLayoutTypes;
然后使用字体描述符创建字体。这里我使用Georgia家族:
NSDictionary *lowercaseNumbers = @{
UIFontFeatureTypeIdentifierKey: @(kNumberCaseType),
UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector),
};
UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes:
@{
UIFontDescriptorFamilyAttribute: @"Georgia",
UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ],
}];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:15];
结果:
编辑:正如 @Random832 指出的那样,Georgia 只有小写数字,因此结果无关紧要。但是,@vikingosegundo 确认此代码适用于支持的字体。谢谢。
顶行是用
生成的
UIFont *font = [UIFont fontWithName:@"DIN Next LT Pro" size:12];
if (font)
label.font = font;
第二行
NSDictionary *lowercaseNumbers = @{ UIFontFeatureTypeIdentifierKey:@(kNumberCaseType), UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector)};
UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes:
@{UIFontDescriptorFamilyAttribute: @"DIN Next LT Pro",UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ]}];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:12];
if (font)
label.font = font;