How to get monospaced numbers in UILabel on iOS 9

前端 未结 8 1177
囚心锁ツ
囚心锁ツ 2020-12-13 06:52

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 lin

8条回答
  •  轮回少年
    2020-12-13 07:36

    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)
    

提交回复
热议问题