swiftsearchuisearchcontrollersearchbaruisearchbardelegate

Trying to set background color of UISearchController in Swift 5


I am trying to set the background color of a UISearchController in Swift 5.

I have tried methods mentioned in other threads but I believe they are outdated.

    searchController.barTintColor = UIColor.redColor()

Error Message: Value of type 'UISearchController' has no member 'barTintColor'


Solution

  •     searchController.searchBar.barTintColor = UIColor.red
        searchController.searchBar.searchBarStyle = .default
    

    i.e
    if your searchBarStyle is .minimal, you won’t be able to change the barTintColor. It will remain white.