0

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'

user10034296
  • 179
  • 1
  • 1
  • 7
  • It is unclear what UI element inside `UISearchController` you want to change the background color? Its view? navigationBar? searchBar? – Kamran Jul 28 '19 at 03:55
  • What does `barTintColor` have to do with background color? – rmaddy Jul 28 '19 at 04:01
  • Try this searchController.view.backgroundColor = .red – A.Munzer Jul 28 '19 at 06:32
  • Sorry, I should clarify. I want to change the color of the searchBar (not the white space where text is entered but the surrounding default gray). It's not the view that I want to change the color of. – user10034296 Jul 28 '19 at 16:13

1 Answers1

4
    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.

Celeste
  • 1,519
  • 6
  • 19