天天看点

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

使用以下方法:

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