首页 > 解决方案 > 无法访问系统小型大写字体

问题描述

我正在使用以下方法获取系统小型大写字体:

    let systemFont = UIFont.systemFont(ofSize: 16.0, weight: UIFont.Weight.regular)
    
    let smallCapsDesc = systemFont.fontDescriptor.addingAttributes([
        UIFontDescriptor.AttributeName.featureSettings: [
            [
                UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType,
                UIFontDescriptor.FeatureKey.typeIdentifier: kUpperCaseSmallCapsSelector
            ]
        ]
    ])
    let smallCapsFont = UIFont(descriptor: smallCapsDesc, size: systemFont.pointSize)
    let smallCapsAttrbs: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : smallCapsFont]

    text.setAttributes(smallCapsAttrbs, range: NSRange(location: start, length: length))

并收到此错误。

CoreText 注意:客户端请求的名称“.SFUI-Regular”,它将获得 TimesNewRomanPSMT 而不是预期的字体。所有系统 UI 字体访问都应通过适当的 API,例如 CTFontCreateUIFontForLanguage() 或 +[UIFont systemFontOfSize:]。

我不确定获得San Francisco字体的 smallCaps 版本的任何其他方式。我该怎么做呢?

标签: iosswiftxcodeuikituifont

解决方案


推荐阅读