直接上代码:
_price = @"27";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString
alloc]
initWithString:_cookPrice.text];
//设置颜色
[attributedString
addAttribute:NSForegroundColorAttributeName
value:[MCUtils
colorWithRGBString:@"#FFA025"]
,
_price.length)]; // 0为起始位置 length是从起始位置開始 设置指定颜色的长度
//设置尺寸
[attributedString
addAttribute:NSFontAttributeName
value:kFont17
,
_price.length)]; // 0为起始位置 length是从起始位置開始 设置指定字体尺寸的长度
//这段代码必需要写 否则没效果
_cookPrice.attributedText = attributedString;