1
-(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;
}

NSMutableAttributedStringfiltertext が totalstring の場合、totalstring で filtertext を申請しています。上記の setattributes が機能している場合、それ以外の場合は部分文字列では機能しません

4

0 に答える 0