我正在尝试使用下面的代码更新搜索栏外观。
searchController.searchBar.searchBarStyle = .prominent
searchController.searchBar.backgroundColor = UIColor.clear
searchController.searchBar.barTintColor = UIColor.black
它不会改变颜色。
或者你可以创建一个搜索栏的出口并做:-
@IBOutlet weak var searchBar: UISearchBar!
searchBar.barTintColor = UIColor.black;
或者你想创建自定义然后:-
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)