Reputation: 576
I have an application in which I use UISearchBar. Everything works fine, just need to search text, for example, colored blue. Example: If you enter into UISearchBar "cod" will appear, for example, the word "xcode" (because "cod" contains) and I needed to "cod" colored blue and the "x" and "e" remained original. Sorry for my English.
Code of my searchBar:
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
if(text.length == 0)
{
isFiltered = FALSE;
}
else
{
isFiltered = true;
filteredTableData = [[NSMutableArray alloc] init];
for (Slova* slova in self.slovoArray)
{
NSRange nameRange = [slova.slovo rangeOfString:text options:NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch|NSWidthInsensitiveSearch ];
if(nameRange.location != NSNotFound)
{
[filteredTableData addObject:slova];
}
}
}
[self.tableView reloadData];
}
Upvotes: 0
Views: 85
Reputation: 7256
That's not possible unless you subclass the search bar and replace it's UITextField with a UITextView and then subclass the UITextView to act as the search bar's text field. It's quite a hassle, so if you don't absolutely need it, you shouldn't spend time implementing it.
I know it's not what you're looking for, but you can change the colour of all the text in the UITextField like this:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];
Upvotes: 1