Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatchKit SF monospaced number

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

like image 390
a developer Avatar asked Jun 29 '15 10:06

a developer


People also ask

What is Apple's default font?

SF Pro is the system font in iOS and iPadOS.

What is iOS font name?

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.


2 Answers

Swift version:

let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular)
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont])
textLabel.setAttributedText(monospacedString)
like image 195
JYeh Avatar answered Nov 18 '22 03:11

JYeh


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];
like image 3
a developer Avatar answered Nov 18 '22 04:11

a developer