3
votes

I cannot seem to find a way to get the "SF Pro Display Heavy Italic" font.

There is UIFont.systemFont(ofSize: CGFloat, weight: UIFont.Weight) but that only gets me all non italic weights.

There is UIFont.italicSystemFont(ofSize: CGFloat) but that only gets me the "Italic Regular"

I want a specific weight of the italic system font (San Francisco Pro)

Or do get the font like a non-system font UIFont(name: String, size: CGFloat)? That seems rather clumsy.

2

2 Answers

2
votes

The above code does work but the one tricky part is for the thicker italic fonts, you need to use (UIFontDescriptorTraitItalic | UIFontDescriptorTraitBold) for the traits, not just UIFontDescriptorTraitItalic.

This is for Semibold, Bold, Heavy and Black fonts (all in italics).

1
votes

Take a look, I use such category for similar reasons.

extension UIFont {

     static func systemFont(ofSize: CGFloat, weight: UIFont.Weight, traits: UIFontDescriptorSymbolicTraits) -> UIFont? {
         let font = UIFont.systemFont(ofSize: ofSize, weight: weight)

         if let descriptor = font.fontDescriptor.withSymbolicTraits(traits) {
             return UIFont(descriptor: descriptor, size: ofSize)
         }

         return nil
     }
}