修改字符串指定范围的颜色
UILabel *textLab = [[UILabel alloc] initWithFrame:CGRectMake(spaceW, totalPriceLab.height+totalPriceLab.y, payView.width-2*spaceW, 30*KSCALE_HEIGHT)]; NSString *timeStr = @"30分钟"; NSString *textStr = [NSString stringWithFormat:@"下单后,请在%@内完成付款",timeStr]; NSMutableAttributedString *attrDescribeStr1 = [[NSMutableAttributedString alloc] initWithString:textStr]; [attrDescribeStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[textStr rangeOfString:timeStr]]; textLab.attributedText = attrDescribeStr1; [payView addSubview:textLab];
posted on 2017-09-28 10:12 Walking_Jin 阅读(225) 评论(0) 编辑 收藏 举报