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.
SF Pro. This neutral, flexible, sans-serif typeface is the system font for iOS, iPad OS, macOS and tvOS. SF Pro features nine weights, variable optical sizes for optimal legibility, four widths, and includes a rounded variant. SF Pro supports over 150 languages across Latin, Greek, and Cyrillic scripts.
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
As of iOS 11, UIFontWeight*
was renamed to UIFont.Weight.*
. More you can get here https://developer.apple.com/documentation/uikit/uifont.weight.
As of iOS 8.2, you can now use UIFont.systemFontOfSize(_ fontSize: CGFloat, weight weight: CGFloat)
:
UIFont.systemFontOfSize(19, weight: UIFontWeightLight)
iOS SDK provided constants for weights:
UIFontWeightUltraLight UIFontWeightThin UIFontWeightLight UIFontWeightRegular UIFontWeightMedium UIFontWeightSemibold UIFontWeightBold UIFontWeightHeavy
Using system font is better than creating a font based on font name when you want to use system fonts since iOS can change their system fonts on iOS (like when they did with Helvetica Neue in iOS 7, and now, San Francisco in iOS 9).
So what I would suggest is to include TTF file of the font you want as use that ttf file as custom font and use the custom font in your app.
This is the special reason why I don't like Apple. Never go what Apple say. Always do what we want. Apple keep on changing Default font for every OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With