一个字符串需要定制某些部分的字体,大小和颜色,此时需要用到
NSAttributedText 和 NSMutableAttributedText 类来实现。
UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(50, 300, 300, 200)];
NSMutableAttributedString *strLabelText = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"我的昵称POKHARA"]];
[strLabelText addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(4,7)];
[strLabelText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 4)];
[strLabelText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(4,7)