<span style="font-size:18px;"> //定义UILabel
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(100,100,200, 50)];
//定义NSMutableAttributedString
NSMutableAttributedString *string = [[NSMutableAttributedStringalloc]initWithString:@"123456789"];
//对range设置颜色
[string addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor]range:NSMakeRange(0,3)];
[string addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(3,3)];
[string addAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor]range:NSMakeRange(6,3)];
//对range设置字体
[string addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:30]range:NSMakeRange(0,4)];
//设置下划线
[string addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:NSMakeRange(4,5)];
label.attributedText = string;
[self.viewaddSubview:label];</span>
<span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: FangSong; font-size: 18px; line-height: 26px;">效果如下</span>
</span>
<span style="font-size:18px;"><span style="color: rgb(29, 148, 33); font-family: FangSong; font-size: 18px; line-height: 26px;">
</span></span>