Like @aliamcami, all of the previous answers did not work as I expected, either the answer did not work for me, or it works, but it takes too much “dummy” code. Therefore, I am sharing another answer written in Swift 4 with simplified logic:
for textField in searchController.searchBar.subviews.first!.subviews where textField is UITextField { textField.subviews.first?.backgroundColor = .white textField.subviews.first?.layer.cornerRadius = 10.5
textField.subviews.first is a subview of "_UISearchBarSearchFieldBackgroundView" that adds visual effects behind the UIFieldEditor .
edited
After some development and a lot of mistakes, I ended up with this elegant solution (which I'm sure Apple will not be happy to approve, but I don’t know) that works with iOS 10 on iOS 12 :
if let textField = searchBar.value(forKey: "searchField") as? UITextField { textField.backgroundColor = myColor
When the searchBar is in tableHeaderView above code can be called in viewWillAppear , but if it is in navigationItem viewWillAppear on iOS 11 and above, it must be called in viewDidAppear .
Ángel Téllez
source share