UILabel 的text显示不同的字体大小和颜色

NSString *text = [NSString stringWithFormat:@"%@或%@",model.bean,model.money];

[self beanPriceBtnAttributTextWithText:text];

//function。。。。

- (void)beanPriceBtnAttributTextWithText:(NSString *)text{

NSRange range = [text rangeOfString:@"或"];

NSRange range0 = NSMakeRange(0, range.location);

NSRange range2 = NSMakeRange(range.location+range.length, text.length-range.location-range.length);

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];

[str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:KFFC043] range:range0];//设置颜色

[str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:K999999] range:range];

[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:range];

[str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:KF1422B] range:range2];//字体大小

[self.beanPrice setAttributedTitle:str forState:UIControlStateNormal];

}

效果


你可能感兴趣的:(UILabel 的text显示不同的字体大小和颜色)