UILable上的字显示不同的颜色和字体,Lable加下划线

颜色和字体

NSMutableAttributedString*str = [[NSMutableAttributedStringalloc]initWithString:[NSStringstringWithFormat:@"由%@发起",model.userName]];

[straddAttribute:NSFontAttributeNamevalue:[UIFontfontWithName:@"Arial-BoldItalicMT"size:16.0]range:NSMakeRange(1,model.userName.length)];

[straddAttribute:NSForegroundColorAttributeNamevalue:kUIColorFromRGB(0x2E8B57)range:NSMakeRange(1,model.userName.length)];

self.userName.attributedText= str;

下划线:

UILabel * phone = [[UILabel alloc]initWithFrame:CGRectMake(135, 70, 200, 30)];

NSMutableAttributedString * content = [[NSMutableAttributedString alloc]initWithString:@"0371-68888999"];

NSRange contentRange = {0,[content length]};

[content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];

[phone setAttributedText:content];

你可能感兴趣的:(UILable上的字显示不同的颜色和字体,Lable加下划线)