【问题标题】:Swift use Small CapsSwift 使用小型大写字母
【发布时间】:2020-04-18 21:45:58
【问题描述】:

如何在 Swift 5 (Storyboard) / Xcode 11 中使用小型大写字母?

Here's what I'm trying to accomplish.

我想出了如何在 SwiftUI 中做到这一点:

Text("Typography")
    .font(Font.system(.body).smallCaps())

但现在不知道如何在 Storyboard-App 中执行此操作。

这是我目前的代码:

labelBrand.font = UIFont.monospacedSystemFont(ofSize: 14, weight: UIFont.Weight.bold)
labelPorsche.font = UIFont.monospacedSystemFont(ofSize: 18, weight: UIFont.Weight.regular)

感谢您的帮助。

【问题讨论】:

    标签: ios swift typography xcode11.4


    【解决方案1】:

    关键是为您想要的系统字体获取一个字体描述符(我们称之为desc),并将小型大写字母作为一项功能应用:

    let d = [
        UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType,
        UIFontDescriptor.FeatureKey.typeIdentifier: kLowerCaseSmallCapsSelector
    ]
    let desc2 = desc.addingAttributes([.featureSettings:[d]])
    

    现在将生成的字体描述符 desc2 转换回 UIFont。

    【讨论】:

    • 感谢您的回复@matt。不幸的是,我不明白如何实现您的代码。我得到了这两个错误:i.stack.imgur.com/LqoOu.png
    猜你喜欢
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 2011-02-03
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    相关资源
    最近更新 更多