UISearchController searchBar doesn't update barTintColor

181 views Asked by At

I'm trying to update the searchbar appearance using bellow code.

    searchController.searchBar.searchBarStyle = .prominent
    searchController.searchBar.backgroundColor = UIColor.clear
    searchController.searchBar.barTintColor = UIColor.black

it doesn't change colors.

1

There are 1 answers

0
Naveen Yadav On

or you can create an outlet of your search bar and do :-

@IBOutlet weak var searchBar: UISearchBar!
searchBar.barTintColor = UIColor.black;

or you want to create custom then :-

var searchBar: UIView = UIView()
var searchField: UISearchBar = UISearchBar();

searchBar.frame = CGRect(x: 0, y: 0, width: xxx, height: xxx)
searchField.barTintColor = UIColor.black;
searchField.frame = CGRect(x: searchBar.frame.origin.x, y: searchBar.frame.origin.y, width: xxx, height: searchBar.frame.height)
searchField.tintColor = UIColor.black
searchBar.addSubview(searchField)