/** 将一个字符串中的特定字符添加颜色 */
- (NSMutableAttributedString *)colorStr:(NSString *)colorStr withColor:(UIColor *)color font:(NSInteger)font {
NSRange range = [self rangeOfString:colorStr];
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:self];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
dic[NSForegroundColorAttributeName] = color;
if (font > 0) {
dic[NSFontAttributeName] = [UIFont systemFontOfSize:font];
}
[attribute addAttributes:dic range:NSMakeRange(range.location,range.length)];
return attribute;
}
- (NSMutableAttributedString *)colorStr:(NSString *)colorStr withColor:(UIColor *)color font:(NSInteger)font {
NSRange range = [self rangeOfString:colorStr];
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:self];
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
dic[NSForegroundColorAttributeName] = color;
if (font > 0) {
dic[NSFontAttributeName] = [UIFont systemFontOfSize:font];
}
[attribute addAttributes:dic range:NSMakeRange(range.location,range.length)];
return attribute;
}