NSString *text = self.model.text;
if (self.model.searchTemplate != nil) {
if ([self.label respondsToSelector:@selector(setAttributedText:)]) {
self.label.text = nil;
NSDictionary *attribs = @{
NSForegroundColorAttributeName: self.label.textColor,
NSFontAttributeName: self.label.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
NSRange redTextRange = [[text lowercaseString] rangeOfString:[self.model.searchTemplate lowercaseString]];
[attributedText setAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]}
range:redTextRange];
self.label.attributedText = attributedText;
} else {
self.label.text = text;
}
} else {
self.label.text = text;
}