Is there any way to set monospaced for San Francisco font in WatchKit? In Introducing the New System Fonts, the presenter only shows for AppKit.
Sample code is appreciated.
Xcode: 7.0 beta WatchOS: 2.0
SF Pro is the system font in iOS and iPadOS.
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.
Swift version:
let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular)
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont])
textLabel.setAttributedText(monospacedString)
Sample code:
UIFont *systemFont = [UIFont systemFontOfSize:20];  
UIFontDescriptor *monospacedNumberFontDescriptor = [systemFont.fontDescriptor fontDescriptorByAddingAttributes: @{  
     UIFontDescriptorFeatureSettingsAttribute: @[@{  
          UIFontFeatureTypeIdentifierKey: @6,  
          UIFontFeatureSelectorIdentifierKey: @0  
     }]  
}];  
UIFont *monospacedNumberSystemFont = [UIFont fontWithDescriptor:monospacedNumberFontDescriptor size:0];  
NSMutableAttributedString *monospacedString = [[NSMutableAttributedString alloc] initWithString:@"1234567890"];  
[monospacedString addAttribute:NSFontAttributeName value:monospacedNumberSystemFont range:NSMakeRange(0, monospacedString.string.length)];  
[label setAttributedText:monospacedString];
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