gpt4 book ai didi

objective-c - 使用中世纪(小写,无衬里)数字

转载 作者:太空狗 更新时间:2023-10-30 03:31:39 25 4
gpt4 key购买 nike

我有客户要求在 iOS 7 项目中使用某种字体,因为它有 medieval numbers .

有什么方法可以为 NSAttributedString 激活这些数字吗?由于使用了默认的内衬数字,它们也包含在字体中。


这是一个例子。两行具有相同的字体,没有变体(常规),一旦激活中世纪数字,第二行使用默认的衬里数字。

enter image description here

最佳答案

这些称为小写数字,可以使用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];

结果:
enter image description here

编辑:正如@Random832 指出的那样,Georgia 只有小写数字,因此结果无关紧要。但是,@vikingosegundo 确认此代码适用于受支持的字体。谢谢。

enter image description here

顶行是用

生成的
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;

关于objective-c - 使用中世纪(小写,无衬里)数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22069706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com