美文网首页
NSMutableAttributeString不同颜色的lab

NSMutableAttributeString不同颜色的lab

作者: 坤哥爱卿 | 来源:发表于2017-07-11 11:32 被阅读36次

NSString*reslutStr =@"27十二月";

NSMutableAttributedString*attriString = [[NSMutableAttributedStringalloc]initWithString:reslutStr];

[attriStringaddAttribute:NSForegroundColorAttributeName//文字颜色

value:[UIColororangeColor]

range:NSMakeRange(2,reslutStr.length-2)];

cell.timeLabel.attributedText= attriString;

+ (void)setUILabel:(UILabel*)label Data:(NSString*)string SetData:(NSString*)setstring Color:(UIColor*)color Font:(CGFloat)font Underline:(BOOL)isbool{

NSRangestr = [label.textrangeOfString:setstring];

if(str.location!=NSNotFound) {

NSMutableAttributedString*str1 = [[NSMutableAttributedStringalloc]initWithString:label.text];

[str1addAttribute:NSForegroundColorAttributeNamevalue:colorrange:NSMakeRange(string.length,setstring.length)];//设置字体颜色

[str1addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:font]range:NSMakeRange(string.length,setstring.length)];

if(isbool) {

//是否显示下划线

[str1addAttribute:NSStrikethroughStyleAttributeNamevalue:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle)range:NSMakeRange(string.length,setstring.length)];

}

label.attributedText= str1;

}

}

相关文章

网友评论

      本文标题:NSMutableAttributeString不同颜色的lab

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