如何在 Swift 中使用 OpenType 功能标签(例如
cv11
)和 UIFont
?
非常简单:
func createFontWithOptionsUI(fontName: String, size: CGFloat) -> UIFont {
let resultFont = UIFontDescriptor(name: fontName, size: size)
.addingAttributes([
.featureSettings: [
"cv11",
1
]
])
// 0.0 means the size from the descriptor will prevail.
return UIFont(descriptor: resultFont, size: 0.0)
}
要与 SwiftUI 一起使用,您只需将其转换为
Font