1

I have a function to set up my Search Controller which I add to View Did Load.

func setUpSearchController() {
        searchController.delegate = self
        searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = true
        searchController.dimsBackgroundDuringPresentation = true
        searchController.searchBar.sizeToFit()
        searchController.searchBar.backgroundColor = .white
        searchController.searchBar.barTintColor = .white
        searchController.searchBar.placeholder = "Search"
        searchController.searchBar.searchBarStyle = .minimal
        searchController.searchBar.tintColor = Colours.brandGreen
        definesPresentationContext = true
        messagesTableView.tableHeaderView = searchController.searchBar
    }

When clicking on the Search Bar the Search Controller dims the background as expected by

searchController.dimsBackgroundDuringPresentation = true

The issue is it also dims the status bar making the UI look ugly. Anyone know how to exclude the status bar from also being dimmed?

As always any help greatly appreciated. Illustration below. Status Bar Illustration

Update

I realise I'm using the Search Controllers Search Bar inside the TableView Header and changing this from

messagesTableView.tableHeaderView = searchController.searchBar

to

navigationItem.searchController = searchController

I get the desired result. However, I'd still like the Search Controllers Search Bar inside the Table Views header.

David Henry
  • 1,972
  • 20
  • 43
  • 1
    if you are not using a proper navigation bar (what would do it for you nicely), you just need to add a view at the top _between_ the top of the main view and the top of the safe area (depends on your view hierarchy but you get the idea, probably) – then set the background colour of the view whatever you'd like and job's has been done. – holex Jul 13 '18 at 10:47
  • Thanks, @holex ill just switch to using it in the navigation controller and have it permanently visible. – David Henry Jul 13 '18 at 11:00

0 Answers0