Not able to set custom fonts in WatchKit

2019-02-15 22:47发布

问题:

I am trying to set Roboto font and have added as target for watch kit extension, but it is still coming as nil. Can we set custom fonts in watch kit.

回答1:

Yes, you can use custom fonts in WatchKit

https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/TextandLabels.html



回答2:

Its worked for me.. Using following Codes.

Add the custom Font to both WatchKit Extension and WatchKit App target Info.plist

Now you write the code following way,

   NSMutableAttributedString *attString =[[NSMutableAttributedString alloc]
     initWithString: @"Yano rocks! Always"];

    [attString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Open Sans" size:20.0]} range:NSMakeRange(0, attString.string.length)];

    [self.loadingLabel setAttributedText:attString];