in Education by
I have two NSStrings: orgText and searchLetter. I want to highlight every occurrences of the searchLetter in the orgText with a red color. How can I get the NSRange of all occurrences of the searchLetter ? for eg : suppose: orgText = "abcahaiapaoiuiapplma" searchLetter = "a". I want to hightlight all "a" occurrences in "abcahaiapaoiuiapplma" with red color. Thanks. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I wrote this method for my project - SUITextView with highlight: - (NSMutableAttributedString*) setColor:(UIColor*)color word:(NSString*)word inText:(NSMutableAttributedString*)mutableAttributedString { NSUInteger count = 0, length = [mutableAttributedString length]; NSRange range = NSMakeRange(0, length); while(range.location != NSNotFound) { range = [[mutableAttributedString string] rangeOfString:word options:0 range:range]; if(range.location != NSNotFound) { [mutableAttributedString setTextColor:color range:NSMakeRange(range.location, [word length])]; range = NSMakeRange(range.location + range.length, length - (range.location + range.length)); count++; } } return mutableAttributedString; } And in my category of NSMutableAttributedString: - (void) setTextColor:(UIColor*)color range:(NSRange)range { // kCTForegroundColorAttributeName [self removeAttribute:(NSString*)kCTForegroundColorAttributeName range:range]; // Work around for Apple leak [self addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)color.CGColor range:range]; }

Related questions

0 votes
    I have two strings both with value null. But when I am comparing the string I have some problem : ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    How will you find out what all files have been changed in a particular Git commit?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    In runtime, I want to retrieve the expire time info about some items in memcached. I didn't find ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    How to get a particular value using the tagged name? (a) getElementbyID() (b) getElementsbyName() (c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    How to get a particular item in the Model in Django?...
asked Jul 2, 2021 in Technology by JackTerrance
0 votes
    Thus a _______ of course data gives the values of all attributes, such as title and department, of all ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any ... in SQL to do this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any ... in SQL to do this? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    How will you get the min alphabetical character from the string?...
asked Nov 25, 2020 in Technology by JackTerrance
0 votes
    How will you get the max alphabetical character from the string?...
asked Nov 25, 2020 in Technology by JackTerrance
0 votes
    Write a program to accept a filename from the user and display all the lines from the file which contain python comment character ‘#’. Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    If n biscuits are distributed among N beggars, find the chance that a particular beggar will get r(A.((N-1)^(n-r))/(N ... -r))/(N^(n))` Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    If n biscuits are distributed among N beggars, find the chance that a particular beggar will get r(A. .^(n)C_(r )((1) ... )D. (r )/(n)` Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    Actually I am checking the excel values whether they are displayed on the web page Mouse hover menu. The menu includes titles and the ... ")); int submenuui = 0; for (int a=1;a...
asked Jul 20, 2022 in Education by JackTerrance
...