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

I am applying NSMutableAttributedString for filtertext in totalstring if filtertext is totalstring then the above setattributes is working otherwise its not working for substrings

Shanti K
  • 2,873
  • 1
  • 16
  • 31
iOSdev
  • 553
  • 5
  • 22
  • I have tried so many posts in stackoverflow which is similar to this qiestion but none of the answers are working for me – iOSdev Dec 02 '14 at 06:42
  • Start by checking the range you are applying the attributes to, so calculate that in the line before setting the attributes and examine it in the debugger. – Droppy Dec 02 '14 at 08:52
  • So the range is correct? – Droppy Dec 02 '14 at 09:05
  • The answer to [this question](http://stackoverflow.com/questions/8520544/applying-different-attributes-for-different-portions-of-an-nsattributedstring) seems to suggest you need to use the `CGColor` of the `UIColor` object to specify the colours, however that is not what the reference says. Might be worth a try though... – Droppy Dec 02 '14 at 09:12
  • There seems to be nothing wrong in that way you are setting the string. I tried out the same code, and it works.. In the case in which it doesn't work, What is the totalString and filterString value that you are using? – Shanti K Dec 03 '14 at 05:43
  • I am using it in cellforrowatindex path method i am passing total string as "Cestrol 175ml RB" and filtertext is "estrol". – iOSdev Dec 03 '14 at 06:01

0 Answers0