2015-06-29 2 views
4

Есть ли способ установить моноширинный шрифт San Francisco в WatchKit? При представлении новых системных шрифтов презентатор показывает только AppKit.WatchKit SF моноширинный номер

Образец кода приветствуется.

Xcode: 7,0 бета WatchOS: 2,0

ответ

2

Пример кода:

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]; 
0

Вы должны использовать SF Compact для компании Apple Watch ..

Apple, часы использует два варианта Сан-Франциско Compact: Display и текста. Эти шрифты были разработаны специально для разборчивости на небольших экранах на .

Для получения дополнительной информации см Typeface раздел этого link.

4

Swift версия:

let monospacedFont = UIFont.monospacedDigitSystemFontOfSize(16, weight: UIFontWeightRegular) 
let monospacedString = NSAttributedString(string: "1234", attributes: [NSFontAttributeName: monospacedFont]) 
textLabel.setAttributedText(monospacedString) 
Смежные вопросы