Background color for UISearchController in UITableView
Solution 1
Set the UITableView's backgroundView to a new useless view:
self.tableView.backgroundView = [UIView new];
Seems illogical, but works like a charm :)
Solution 2
Cameron E's correct answer in Swift:
tableView.backgroundView = UIView()
Note that self.tableView.backgroundView = nil
does not work.
Solution 3
Try this:
[searchController.searchBar setBarTintColor:[UIColor blackColor]];
[searchController.searchBar setTintColor:[UIColor whiteColor]];
Hope this helps.
Solution 4
Just set an empty view as the UITableView's backgroundview
[self.tableView setBackgroundView:[[UIView alloc] initWithFrame:CGRectZero]];
Related videos on Youtube
Ryan Bobrowski
Full-stack developer for Ad Age and owner of Brooklyn-based Hat Trick Designs. Currently enjoying Laravel, iOS/Swift, and traveling the world.
Updated on July 05, 2022Comments
-
Ryan Bobrowski almost 2 years
I have a SearchController's search bar inserted programatically into a UITableView's tableHeaderView. When I pull up to view the search bar or refresh the table, I get this weird darker gray that you can see in the following image, in between the refresher activity indicator and the search bar (this background color persists even when I remove the refresher view):
tableView.tableHeaderView = searchController.searchBar
I've tried changing this background color in every way I can think of:
tableView.backgroundColor = UIColor.redColor() tableView.tableHeaderView!.backgroundColor = UIColor.redColor() searchController.searchBar.backgroundColor = UIColor.redColor() view.backgroundColor = UIColor.redColor()
Nothing works. This dark gray isn't one of the custom colors I use in my project so I know I didn't set it manually. As soon as I take out the searchController everything works just like before: that dark gray is replaced by the lighter gray seen everywhere else.
-
streem almost 9 yearssearchController.view.backgroundColor = UIColor.redColor() ?
-
Ryan Bobrowski almost 9 yearsI don't actually want it red, just checking what works. None of those change that dark gray background color.
-
Karlos almost 9 yearsTry this it might be helpful self.tableView.contentOffset = CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height)
-
-
dustinrwh over 7 yearsThis is just what I was looking for.