我建立我的第一個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」或其他字體? –