如何将 OpenType 功能标签与 UIFont 结合使用?

问题描述 投票:0回答:1

如何在 Swift 中使用 OpenType 功能标签(例如

cv11
)和
UIFont

swift swiftui uifont opentype
1个回答
0
投票

非常简单:

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

© www.soinside.com 2019 - 2024. All rights reserved.