iOS 设置Label中特定的文字大小跟颜色

iOS 设置Label中特定的文字大小和颜色

直接上代码:

_price = @"27";

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_cookPrice.text];

//设置颜色

    [attributedString addAttribute:NSForegroundColorAttributeName value:[MCUtils colorWithRGBString:@"#FFA025"] range:NSMakeRange(0, _price.length)]; // 0为起始位置 length是从起始位置开始 设置指定颜色的长度


//设置尺寸

    [attributedString addAttribute:NSFontAttributeName value:kFont17 range:NSMakeRange(0, _price.length)]; // 0为起始位置 length是从起始位置开始 设置指定字体尺寸的长度

   //这段代码必须要写 否则没效果

    _cookPrice.attributedText = attributedString;