Search code examples
iosios8ios9uifont

System font for both iOS 8 and iOS 9


I want to support both iOS 8 and iOS 9 systems for my app. And maybe iOS 7. As we know, system font for iOS 7 and 8 is Helvetica Neue. But in iOS 9 system font is San-Francisco. And if you don't set Helvetica font explicitly via [UIFont fontWithName:@"HelveticaNeue" size:15];, but use [UIFont systemFontOfSize:15];, you'll get Helvetica for iOS 7 and 8 and San-Francisco for iOS 9 automatically. And it's great! For interface builder's labels and buttons you can set thin, ultra thin, medium etc. system fonts. It is great too. But how can I set these thin, ultra, medium system fonts in code, programmatically? Do I need to create a category with a fork for iOS 9 and previous iOS?


Solution

  • Use + systemFontOfSize:weight:. It's available for iOS 8 and above.

    For iOS 7, interface builder settings will work, and for code you will need to create a UIFontDescriptor with the appropriate weight.