設定文字中不同字型顏色
阿新 • • 發佈:2019-02-17
- (void)viewDidLoad {
NSRange range = [orderPriceLabel.text rangeOfString:@"付款金額:"];
[self setTextColor:orderPriceLabel FontNumber:_kFontMain AndRange:range AndColor:kColor262626];
}
//設定不同字型顏色
-(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;
}