NSDictionary *attributes1 = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0f]};
NSAttributedString *string1 = [[NSAttributedString alloc] initWithString:@"0123" attributes:stringAttributes1];
NSDictionary *attributes2 = @{NSForegroundColorAttributeName: [UIColor redColor],
NSFontAttributeName: [UIFont boldSystemFontOfSize:16.0f]};
NSAttributedString *string2 = [[NSAttributedString alloc] initWithString:@"456" attributes:stringAttributes2];
NSDictionary *attributes3 = @{NSForegroundColorAttributeName: [UIColor greenColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0f]};
NSAttributedString *string3 = [[NSAttributedString alloc] initWithString:@"789" attributes:stringAttributes3];
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] init];
[mutableAttributedString appendAttributedString:string1];
[mutableAttributedString appendAttributedString:string2];
[mutableAttributedString appendAttributedString:string3];
label.attributedText = mutableAttributedString;
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
NSAttributedStringで指定できる属性
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
NSFontAttributeName フォント。UIFontを指定
NSParagraphStyleAttributeName NSParagraphStyleオブジェクトを指定
NSForegroundColorAttributeName 文字色。UIColorを指定
NSBackgroundColorAttributeName 文字背景色。UIColorを指定
NSKernAttributeName 文字間隔。floatをNSNumberで指定。@12.0fのようにすると良いだろう
NSUnderlineStyleAttributeName アンダーラインを表示するか否か。integer(0 or 1)をNSNumberで指定。1のとき表示
NSStrokeColorAttributeName 縁取りの色。UIColorを指定
NSStrokeWidthAttributeName 縁取りの幅。floatをNSNumberで指定。@2.0fのようにすると良いだろう。
正の値のときは縁取りの内側はclearColorになる。
負の値のときは縁取りの内側を文字色(NSForegroundColorAttributeName)で塗りつぶす。
NSShadowAttributeName 文字の影。NSShadowを指定
NSString *const NSFontAttributeName; // フォント名
NSString *const NSParagraphStyleAttributeName; // 段落の書式
NSString *const NSForegroundColorAttributeName; // 文字色
NSString *const NSBackgroundColorAttributeName; // 背景色
NSString *const NSLigatureAttributeName; // リガチャ
NSString *const NSKernAttributeName; // カーニング
NSString *const NSStrikethroughStyleAttributeName; // 取り消し線
NSString *const NSUnderlineStyleAttributeName; // 下線
NSString *const NSStrokeColorAttributeName; // 枠線の色
NSString *const NSStrokeWidthAttributeName; // 枠線の幅
NSString *const NSShadowAttributeName; // 影
NSString *const NSVerticalGlyphFormAttributeName; // 縦書き
最終更新:2015年10月27日 13:07