标签: variable-fonts

iOS 14 中的可变字体

以下代码允许创建具有不同权重的字体。

func makeFont(weight: CGFloat, size: CGFloat) -> UIFont {
    var attributesDict = [String: Any]()
    attributesDict["Weight"] = weight
    /* Rubik-Light - is a variable font */
    let fontDescriptor = UIFontDescriptor(
        fontAttributes: [
            UIFontDescriptor.AttributeName.name : "Rubik-Light",
            kCTFontVariationAttribute as UIFontDescriptor.AttributeName : attributesDict
        ]
    )
    return UIFont(descriptor: fontDescriptor, size: size)
}
Run Code Online (Sandbox Code Playgroud)

它在 ios 13 及更低版本上运行良好,但在 iOS 14 上不起作用。有什么解决方案吗?

ios swift uifontdescriptor ios14 variable-fonts

0
推荐指数
1
解决办法
326
查看次数

标签 统计

ios ×1

ios14 ×1

swift ×1

uifontdescriptor ×1

variable-fonts ×1