3

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.

Marmelador
  • 790
  • 5
  • 22
  • 1
    Take a look at this https://stackoverflow.com/questions/45036080/trying-to-get-sf-pro-display-thin-italics-on-ios and this https://stackoverflow.com/questions/4713236/how-do-i-set-bold-and-italic-on-uilabel-of-iphone-ipad/21777132#21777132 – 0rt Feb 21 '18 at 18:01

2 Answers2

2

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).

Werner Sharp
  • 121
  • 1
  • 1
  • 6
1

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
     }
}
Oleg
  • 418
  • 4
  • 13