I want to create a UIFont that is both black in weight (heavier than bold) and italic, without hardcoding any font names or anything.
All my attempts have came up short. You can do it via UIFont.systemFont(ofSize: 15.0, weight: .black) and then applying an italic symbolic trait, but that obviously only works with the system font. (Helvetica and Avenir both for instance come in various font weights that include italic variants.)
Here is my attempt, but it comes up with just a regular weight italic font, not black.
var fontAttributes: [UIFontDescriptor.AttributeName: Any] = [:]
var fontTraits: [UIFontDescriptor.TraitKey: Any] = [:]
fontTraits[.weight] = UIFont.Weight.black // Also hardcoding a number like 0.6 does not work
fontAttributes[.traits] = fontTraits
let descriptor1 = UIFontDescriptor(fontAttributes: fontAttributes)
let descriptor2 = descriptor1.withSymbolicTraits(.traitItalic)!
let font = UIFont(descriptor: descriptor2, size: 19.0)
label.font = font // Sad trombone music. It's just 'regular italic'.