iOS设置同一个Label的不同颜色的字体

来源:互联网 发布:黑龙江大学网络教育 编辑:程序博客网 时间:2024/05/05 04:41

使用以下方法:
priceStr = @”¥28888/月”;
NSMutableAttributedString *price =[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@”%@”,priceStr]];
NSRange blankRange = NSMakeRange([[price string] rangeOfString:@”/月”].location, [[price string] rangeOfString:@”/月”].length);
[price addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:blankRange];
[self.priceLabel setAttributedText:price];

1 0
原创粉丝点击