How to get monospaced numbers in UILabel on iOS 9

Samuel Mellert picture Samuel Mellert · Jun 15, 2015 · Viewed 12.9k times · Source

At WWDC 2015, there was a session about the new “San Francisco” system font in iOS 9. It uses proportional number rendering instead of monospaced numbers by default when linked against the iOS 9 SDK. There is a convenient initializer on NSFont called NSFont.monospacedDigitsSystemFontOfSize(mySize weight:) that can be used to explicitly enable monospaced number display.

However I couldn't find the UIKit equivalent for this on UIFont.

Answer

Ric Santos picture Ric Santos · Aug 29, 2015

This is now available in UIFont since iOS 9:

+ (UIFont *)monospacedDigitSystemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight NS_AVAILABLE_IOS(9_0);

eg:

[UIFont monospacedDigitSystemFontOfSize:42.0 weight:UIFontWeightMedium];

or in Swift:

UIFont.monospacedDigitSystemFont(ofSize: 42.0, weight: UIFontWeightMedium)