I want to change color of No Results in search controller. I can change the search table background color separate indexcolor.
Asked
Active
Viewed 52 times
1 Answers
0
try like this,
create a property
@property (nonatomic, strong) UISearchController * searchController;
then add following:
// When the user types in the search bar, this method gets called.
- (void)updateSearchResultsForSearchController:(UISearchController *)aSearchController {
//// .. do whatever your search results..
for (UIView *subview in ((UITableViewController *)self.searchController.searchResultsController).tableView.subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
if ([((UILabel *)subview).text isEqualToString:@"No Results"]) {
((UILabel *)subview).textColor = [UIColor redColor];
}
}
}
}
Edited Ans:
for (UIView *subview in self.searchDisplayController.searchResultsTableView.subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
if ([((UILabel *)subview).text isEqualToString:@"No Results"]) {
((UILabel *)subview).textColor = [UIColor redColor];
}
}
}

Antony Raphel
- 2,036
- 2
- 25
- 45
-
how you implemented **UISearchController**? Is it like this `[[UISearchController alloc] initWithSearchResultsController:searchResultsController]`? – Antony Raphel Apr 19 '17 at 08:18
-
I use it like" self.searchDisplayController.searchResultsTableView" – shirish Apr 19 '17 at 10:57
-
Updated ans, check it n let me know – Antony Raphel Apr 19 '17 at 11:35
-
you are welcome, accept the ans and vote it if you want to support me :) – Antony Raphel Apr 19 '17 at 13:19