UILabel設(shè)置不同的字體顏色
來源:程序員人生 發(fā)布時間:2015-05-22 08:35:50 閱讀次數(shù):3023次
NSMutableAttributedString
*str
= [[
NSMutableAttributedString
alloc]
initWithString:@
"Using
NSAttributed String"
];
[str
addAttribute:
NSForegroundColorAttributeName
value:[UIColor
blueColor] range:
NSMakeRange
(0,5)];
[str
addAttribute:
NSForegroundColorAttributeName
value:[UIColor
redColor] range:
NSMakeRange
(6,12)];
[str
addAttribute:
NSForegroundColorAttributeName
value:[UIColor
greenColor] range:
NSMakeRange
(19,6)];
[str
addAttribute:
NSFontAttributeName
value:[UIFont
fontWithName:@
"Arial-BoldItalicMT"
size:30.0]
range:
NSMakeRange
(0,
5)];
[str
addAttribute:
NSFontAttributeName
value:[UIFont
fontWithName:@
"HelveticaNeue-Bold"
size:30.0]
range:
NSMakeRange
(6,
12)];
[str
addAttribute:
NSFontAttributeName
value:[UIFont
fontWithName:@
"Courier-BoldOblique"
size:30.0]
range:
NSMakeRange
(19,
6)];
attrLabel.attributedText
= str;
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈