Label显示不同颜色字体等的字符串

2017-12-14  本文已影响0人  WTF丶程序猿

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,50,300,40)];

[self.viewaddSubview:label];

NSString*string =@"¥300   ¥322";

NSString*subString =@"¥322";

NSRangerange = [stringrangeOfString:subString];

NSMutableAttributedString*attri = [[NSMutableAttributedStringalloc]initWithString:stringattributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleNone)}];

[attriaddAttribute:NSStrikethroughStyleAttributeNamevalue:@(NSUnderlineStyleSingle)range:range];

[attriaddAttribute:NSForegroundColorAttributeNamevalue:[UIColororangeColor]

range:range];

[attriaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20]

range:range];

label.attributedText= attri;

上一篇 下一篇

猜你喜欢

热点阅读