Background color for UISearchController in UITableView
Asked Answered
G

5

23

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):

enter image description here

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.

Grosmark answered 16/7, 2015 at 19:55 Comment(3)
searchController.view.backgroundColor = UIColor.redColor() ?Fixate
I don't actually want it red, just checking what works. None of those change that dark gray background color.Grosmark
Try this it might be helpful self.tableView.contentOffset = CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height)Corroborant
E
50

Set the UITableView's backgroundView to a new useless view:

    self.tableView.backgroundView = [UIView new];

Seems illogical, but works like a charm :)

Easton answered 7/10, 2015 at 10:4 Comment(0)
G
17

Cameron E's correct answer in Swift:

tableView.backgroundView = UIView()

Note that self.tableView.backgroundView = nil does not work.

Gratitude answered 28/3, 2016 at 20:17 Comment(0)
I
10

Try this:

[searchController.searchBar setBarTintColor:[UIColor blackColor]];
[searchController.searchBar setTintColor:[UIColor whiteColor]];

Hope this helps.

Intermission answered 1/9, 2015 at 10:53 Comment(1)
This is just what I was looking for.Buote
A
4

Just set an empty view as the UITableView's backgroundview

[self.tableView setBackgroundView:[[UIView alloc] initWithFrame:CGRectZero]];
Absent answered 21/9, 2015 at 10:53 Comment(0)
U
-1

try to change color of

self.navigationController?.navigationBar = UIColor(red: 1, green: 1, blue: 1, alpha: 1)

Utrillo answered 4/6, 2019 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.