はそれを行う方法です:
NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:@"$5.50"];
[attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:NSMakeRange(0, 1)];
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 1)];
[attStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17.0] range:NSMakeRange(1, 4)];
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(1, 4)];
、代わりにsetText
のsetAttributedText
を使用することを忘れないでください:
[myLabel setAttributedText:attStr];
http://stackoverflow.com/questions/1417346の可能性の重複/ iphone-uilabel-containing-multiple-fonts-at-the-time – yuji
「それはUILabelでなければならない」 - なぜですか? – bneely
@yujiと同意します。 'UILabel'は' NSAttributedString'を取っていません。 'UITextField'や' UITextView'も実行しません。あなたはそれらのコアテキストに入り、それは醜いです。 ref'd質問の解決策は、Core Textをダイビングするよりはるかに簡単です。 – smparkes