iOS: Exclude digits from the effects of small caps

こ雲淡風輕ζ 提交于 2020-12-15 05:45:30

问题


I'm applying small caps to lower case letters, but it appears that it also includes all digits. This is also true when I apply it only to uppercase letters.

Is there any way to exclude digits from the effect of small caps (like the label for wind speed/direction in the stock Weather app), or do I need to resort to an attributed string for that effect?

Currently I'm just applying a font to all label content:

extension UIFont {
    func smallCaps() -> UIFont {
        let settings: [[UIFontDescriptor.FeatureKey : Int]] = [
            [
                .featureIdentifier : kLowerCaseType,
                .typeIdentifier : kLowerCaseSmallCapsSelector
            ]
        ]
        let attributes: [UIFontDescriptor.AttributeName : Any] = [.featureSettings: settings]
        
        return UIFont(descriptor: self.fontDescriptor.addingAttributes(attributes), size: self.pointSize)
    }
}

I tried using kNumberCaseType and kUpperCaseNumbersSelector in the same vein as the above code, but I guessed wrong. According to the documentation it turned out not to be what I was looking for.

来源:https://stackoverflow.com/questions/65041221/ios-exclude-digits-from-the-effects-of-small-caps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!