WatchKit SF 等宽数字
WatchKit SF monospaced number
有什么方法可以在 WatchKit 中为 San Francisco 字体设置等宽字体? Introducing the New System Fonts, the presenter only shows for AppKit.
感谢示例代码。
Xcode:7.0 测试版
手表操作系统:2.0
您需要使用 SF Compact
Apple Watch..
Apple Watch uses two variants of the San Francisco Compact: Display
and Text. These fonts were designed specifically for legibility on
small screens.
有关详细信息,请参阅此 link.
的 Typeface
部分
示例代码:
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];
Swift版本:
let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular)
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont])
textLabel.setAttributedText(monospacedString)
Swift 4
extension WKInterfaceLabel {
func setMonospacedText(_ text: String) {
let monospacedFont = UIFont.monospacedDigitSystemFont(ofSize: 16, weight: UIFont.Weight.regular)
let attributedString = NSAttributedString(string: text, attributes: [NSAttributedStringKey.font: monospacedFont])
self.setAttributedText(attributedString)
}
}
有什么方法可以在 WatchKit 中为 San Francisco 字体设置等宽字体? Introducing the New System Fonts, the presenter only shows for AppKit.
感谢示例代码。
Xcode:7.0 测试版 手表操作系统:2.0
您需要使用 SF Compact
Apple Watch..
Apple Watch uses two variants of the San Francisco Compact: Display and Text. These fonts were designed specifically for legibility on small screens.
有关详细信息,请参阅此 link.
的Typeface
部分
示例代码:
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];
Swift版本:
let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular)
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont])
textLabel.setAttributedText(monospacedString)
Swift 4
extension WKInterfaceLabel {
func setMonospacedText(_ text: String) {
let monospacedFont = UIFont.monospacedDigitSystemFont(ofSize: 16, weight: UIFont.Weight.regular)
let attributedString = NSAttributedString(string: text, attributes: [NSAttributedStringKey.font: monospacedFont])
self.setAttributedText(attributedString)
}
}