In iOS 13 and low I got Font.Weight using this extension for UIFont
var weight: UIFont.Weight {
guard let traits = fontDescriptor.object(forKey: .traits) as? [UIFontDescriptor.TraitKey: Any], let weightValue = traits[.weight] as? CGFloat else { return .regular }
let weight = UIFont.Weight(rawValue: weightValue)
return weight
}
But since iOS 14 weightValue is wrong. For example:
let font = UIFont(name: "AvenirNext-Bold", size: 21)
print(font?.weight.rawValue)
print(font?.weight == .bold)
iOS 14 - 0.40000000000000002 false
iOS 13 - 0.40000000596046448 true
Anybody faced with it?