- (
void)viewDidLoad {
NSRange range = [_amountLabel
.text rangeOfString:@
"0.00"];
[
self setTextColor:_amountLabel FontNumber:[
UIFont systemFontOfSize:
13] AndRange:range AndColor:[
UIColor orangeColor]];
}
-(
void)setTextColor:(
UILabel *)label FontNumber:(
id)font AndRange:(
NSRange)range AndColor:(
UIColor *)vaColor
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label
.text];
[str addAttribute:NSFontAttributeName value:font range:range];
[str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
label
.attributedText = str;
}
例如:356.00元 只显示数字是红色 元是原来的色调
NSRange range2 = [cell.moneyLabel.text rangeOfString:@"元"];
NSRange range22 = NSMakeRange (0,range2.location);
[self setTextColor:cell.moneyLabel FontNumber:[UIFont systemFontOfSize:15] AndRange:range22 AndColor:[UIColor redColor]];
效果:
转载请注明原文地址: https://ju.6miu.com/read-667662.html