0
votes

I am facing issue to set bg color of UISearchBar as White. I have tried to set bg as white but still default gray bg color is there. I tried this code.

searchController?.searchBar.searchTextField.backgroundColor = UIColor.white

I dont understand what's wrong. Bcz when i set any color like green or red, they are set easily. Please provide answer in Swift 4+ .

2

2 Answers

0
votes

Use the below in Appdelegate

if #available(iOS 13, *) {
    UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = . white
}
0
votes

We can't set background color of SearchBar as white.

As we can see all Apple default Apps doesn't have white BG color,

Solution: We need to make customised SearchBar for that.