-1

I want to change color of No Results in search controller. I can change the search table background color separate indexcolor.

Antony Raphel
  • 2,036
  • 2
  • 25
  • 45
shirish
  • 11
  • 6

1 Answers1

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