Ing. Ron
Ing. Ron

Reputation: 2095

How to use a monospaced font in WatchKit

In my WatchKit layout I need to have a monospaced font. Do I have to add a monospaced font or is there any trick to use the system font?

Upvotes: 0

Views: 319

Answers (2)

Ric Santos
Ric Santos

Reputation: 16447

You can use the system font (San Fransisco) which has a monospaced variant.

For WKInterfaceLabel, this is not a visible option in interface builder, and you cannot access the font property, so you must use an attributed string to set it:

UIFont *monospacedFont = [UIFont monospacedDigitSystemFontOfSize:36.0 weight:UIFontWeightRegular];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"12:34:56"
                                                                       attributes:@{NSFontAttributeName: monospacedFont}];
[self.label setAttributedText:attributedString];

Upvotes: 1

cnoon
cnoon

Reputation: 16663

You will need to add it manually. Apple has some good instructions here in the programming guide. Additionally, here are a couple other threads that have a bit more trouble shooting detail.

Upvotes: 2

Related Questions