-(NSMutableAttributedString *)getAttributedStringforString:(NSString *)totalString filtertext:(NSString *)filtertext font:(UIFont *)titlefont backgroundColor:(UIColor *)bcolor foregroundColor:(UIColor *)fcolor
{
NSMutableAttributedString *attributedString = nil;
NSDictionary *filterTextAttribute = @{NSBackgroundColorAttributeName:bcolor, NSForegroundColorAttributeName:fcolor, NSFontAttributeName: titlefont};
attributedString = [[NSMutableAttributedString alloc] initWithString:totalString];
[attributedString beginEditing];
[attributedString setAttributes:filterTextAttribute range:[totalString rangeOfString:filtertext options:NSCaseInsensitiveSearch]];
[attributedString endEditing];
return attributedString;
}
如果filtertext是totalstring,那么我在totalstring中对filtertext应用NSMutableAttributedString
,那么上面的setattributes正在工作,否则它不适用于子字符串