I'm trying to use a variable font on a label in UIKitView, but the variations are not applying. What could I be doing wrong?
Dovydas
03/27/2025, 4:03 PM
Copy code
val baseFont = UIFont.preferredFontForTextStyle(UIFontTextStyleLargeTitle)
val variations = mapOf(
2003265652 to 900, // wght
2003072104 to 140 // wdth
)
val fontAttributes = mapOf(
UIFontDescriptorAttributeName to baseFont.fontName,
"NSCTFontVariationAttribute" as UIFontDescriptorAttributeName to variations
)
val descriptor = baseFont.fontDescriptor.fontDescriptorByAddingAttributes(fontAttributes)
val variableFont = UIFont.fontWithDescriptor(descriptor, baseFont.pointSize)
label.font = variableFont