我建立我的第一个WatchKit应用程序时遇到的麻烦与NSAttributedString
格式,因为它似乎不工作,我会期望;)WatchKit,AttributedString格式不工作
这是我的代码:
UIFont *textFont = [UIFont fontWithName:@"Menlo" size:30];
UIFont *hlFont = [UIFont fontWithName:@"Menlo-Bold" size:30];
NSMutableAttributedString *information = [[NSMutableAttributedString alloc]initWithString:@"ADDED AN ENTRY OF " attributes:@{NSFontAttributeName : textFont}];
NSString *amountString = [NSString stringWithFormat:@"%.2f",(-1)*handler.amount.floatValue];
NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];
NSAttributedString *amount = [[NSAttributedString alloc]initWithString:amountString attributes:@{NSFontAttributeName : hlFont, NSUnderlineStyleAttributeName : underline }];
NSAttributedString *to = [[NSMutableAttributedString alloc]initWithString:@" TO " attributes:@{NSFontAttributeName : textFont}];
NSString *categoryString = handler.category;
NSAttributedString *category = [[NSAttributedString alloc]initWithString:categoryString attributes:@{NSFontAttributeName : hlFont, NSUnderlineStyleAttributeName : underline }];
[information appendAttributedString:amount];
[information appendAttributedString:to];
[information appendAttributedString:category];
[_informationLabel setAttributedText:information];
和这个结果:
期望
10.00
和Stuff
应以下划线和粗体显示。
与iOS上的属性字符串如何工作有什么根本不同?我错过了什么?
*将在24小时内接受 –
不知道为什么我们无法在苹果手表中使用字体“Menlo”或其他字体? –