美文网首页iOS开发专区
UILable上的字显示不同的颜色和字体,Lable加下划线

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

作者: 我的天空蔚蓝色 | 来源:发表于2015-11-11 23:31 被阅读236次

颜色和字体

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加下划线

    本文链接:https://www.haomeiwen.com/subject/xcvhhttx.html