ios - Swift 使用小型大写字母
问题描述
如何在 Swift 5 (Storyboard) / Xcode 11 中使用小型大写字母?
我想出了如何在 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)
谢谢你的帮助。
解决方案
关键是获取您想要的系统字体的字体描述符(我们称之为desc
),并将小型大写字母应用为功能:
let d = [
UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType,
UIFontDescriptor.FeatureKey.typeIdentifier: kLowerCaseSmallCapsSelector
]
let desc2 = desc.addingAttributes([.featureSettings:[d]])
现在将生成的字体描述符转换desc2
回 UIFont。
推荐阅读
- javascript - 将父/子结构转换为对象
- excel - 运行两个 Internet Explorer 实例
- java - 订购一个 ArrayList
基于特定值 - python - 使用用户类型在 Django 中不起作用
- wpf - 如何为属性值右侧的小方块添加特征(在属性窗口中)?
- php - 未显示任何错误消息,但使用 PHP 的 BigQuery 中没有数据
- c++ - 使用 sizeof() 确定 ArraySize
- flask - 使用布尔值或日期时,sqlalchemy 案例无法正常工作
- c# - 以编程方式调整 Azure 虚拟机大小的语法
- ruby-on-rails - Rails:使用强参数作为关键字参数