Search code examples
fontslabelnsattributedstringwatchkitapple-watch

Apple Watch can't change font in label


I can't change font in label. I added "Font provided by application" in Info.plist in WatchKit App and WatchKit Extension and added font in Bundle Recourse both project. When I compiled code with for (NSString* family in [UIFont familyNames]) NSLog(@"|%@"",family); The list of all the fonts I find that is connected: "|Courier New|" But it not work:

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

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

    [self.loadingLabel setAttributedText:attString];

or

UIFont* labelFont = [UIFont fontWithName:@"Courier New" size:16];
NSAttributedString* lab = [[NSAttributedString alloc] 
initWithString:@"Text" attributes:@{NSFontAttributeName: labelFont}];
[self.label setAttributedText:lab];

Also, any system font does not work!

Pls, help!

p.s. I did everything according to instructions: [link] (http://www.tech-recipes.com/rx/53710/how-do-i-use-custom-fonts-in-my-apple-watch-app/)

I use Watch App(not Notification and Glance).


Solution

  • I have understood what was the problem. Xcode does not establish a standard fonts such as Arial, Courier and etc., but installs fonts that are not in the system and downloaded from the Internet. So when I put Arial and Courier and nothing happened.