I'd like to get an italic version of a light font, for example "HelveticaNeue-Light".
Using a fontDescriptor
gives me the italic version of the 'regular' "Helvetica Neue" instead of the italic "HelveticaNeue-Light". I could retrieve the fontDescriptor.fontAttributes
and update the UIFontDescriptor.AttributeName.name
, but that's tricky, because the naming is different per font ("HelveticaNeue" uses "Italic", Helvetica uses "Oblique").
let lightFont = UIFont(name: "HelveticaNeue-Light", size: 16.0)!
var lightFontDescriptor = lightFont.fontDescriptor.withSymbolicTraits([.traitItalic])!
var lightFontWithItalicTraits = UIFont(descriptor: lightFontDescriptor, size: 0)
// <UICTFont: ..> font-family: "HelveticaNeue-Light"; font-weight: normal; font-style: normal; font-size: 16.00pt
print(lightFont)
// <UICTFont: ..> font-family: "Helvetica Neue"; font-weight: normal; font-style: italic; font-size: 16.00pt
print(lightFontWithItalicTraits)
// The font I expect:
let lightItalicFont = UIFont(name: "HelveticaNeue-LightItalic", size: 16.0)!
// <UICTFont: ..> font-family: "HelveticaNeue-LightItalic"; font-weight: normal; font-style: italic; font-size: 16.00pt
print(lightItalicFont)
Any other idea how to get the italic version of an existing font?