WatchKit SF等宽数字

a d*_*per 5 objective-c ios swift watchkit xcode7

有没有办法在WatchKit中为旧金山字体设置monospaced?在介绍新系统字体时,演示者仅显示AppKit.

示例代码表示赞赏.

Xcode:7.0 beta WatchOS:2.0

JYe*_*Yeh 5

迅捷版:

let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular)
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont])
textLabel.setAttributedText(monospacedString)
Run Code Online (Sandbox Code Playgroud)


a d*_*per 3

示例代码:

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];
Run Code Online (Sandbox Code Playgroud)