直接上代码:

_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;


posted on 2017-05-08 16:55  lxjshuju  阅读(350)  评论(0编辑  收藏  举报