I am trying to add a system font of weight "Heavy" (not bold) and also try to make it italic. I saw other stackoverflow solutions but it does not seem to work. Here is what I have done:
let percentageLabel: UILabel = {
let label = UILabel()
label.text = "0"
label.textAlignment = .center
label.textColor = .white
label.font = UIFont.systemFont(ofSize: 32, weight: .heavy, traits: .traitItalic)
return label
}()
Extension as suggested in a stack overflow post
extension UIFont {
static func systemFont(ofSize: CGFloat, weight: UIFont.Weight, traits: UIFontDescriptor.SymbolicTraits) -> UIFont? {
let font = UIFont.systemFont(ofSize: ofSize, weight: weight)
if let descriptor = font.fontDescriptor.withSymbolicTraits(traits) {
return UIFont(descriptor: descriptor, size: ofSize)
}
return nil
}
}
Thing is when I tried all suggested solutions, bold and italic seems to work BUT black and italic doesn't work. It is still rendered as regular italic.
