Search code examples
iosobjective-cswiftuikituifont

UIFont - how to get system thin font


UIFont has methods to get regular font (systemFontOfSize) or bold font (boldSystemFontOfSize), but how to get a "thin system font" available through storyboard?

Passing "system-thin" to UIFont Contructor doesn't work, this constructor only works for non system fonts.


Solution

  • You can use system font thin weight:

    UIFont.systemFont(ofSize: 34, weight: UIFontWeightThin)
    

    List of available weights for San Francisco:

    UIFontWeightUltraLight
    UIFontWeightThin
    UIFontWeightLight
    UIFontWeightRegular
    UIFontWeightMedium
    UIFontWeightSemibold
    UIFontWeightBold
    UIFontWeightHeavy
    UIFontWeightBlack
    

    san francisco font weights

    As of iOS 11, UIFontWeight* was renamed to UIFont.Weight.*. More you can get here https://developer.apple.com/documentation/uikit/uifont.weight.