Search code examples
iosswiftuitableviewuisearchcontroller

Change Status Bar Background in Search Controller


I am trying to change my Status Bar background color but I seem not to be doing it right.

Here's a Screenshot of my simulator:

Screenshot

As you can see, when search bar is active, the status bar background changes to white.

The idea is to use the same background color with the search controller when search controller is active.

Here is the code I used:

class DisplayListTVC: UITableViewController, UISearchResultsUpdating {
    var resultSearchController = UISearchController()

...

override func viewDidLoad() {
    super.viewDidLoad()

    self.resultSearchController = UISearchController(searchResultsController:nil)
    self.resultSearchController.searchResultsUpdater = self
    self.resultSearchController.dimsBackgroundDuringPresentation = false
    self.resultSearchController.searchBar.sizeToFit()

    self.resultSearchController.searchBar.barTintColor = UIColor(red:0.73, green:0.81, blue:0.87, alpha:1.0)

    self.resultSearchController.searchBar.tintColor = UIColor(red:1.00, green:1.00, blue:1.00, alpha:1.0)

}

Solution

  • I know what you mean, I had the same problem. I found a solution, so you can still see the status bar. Just had this two lines of code in your function and it will look much better after ;) However I don't know how to change the color, it will be grey. Tell me what you think about it ;)

    self.tableView.tableHeaderView = controller.searchBar
            self.definesPresentationContext = true