我正在尝试使用以下代码更新搜索栏外观。
searchController.searchBar.searchBarStyle = .prominent
searchController.searchBar.backgroundColor = UIColor.clear
searchController.searchBar.barTintColor = UIColor.black
它不会改变颜色。
答案 0 :(得分:0)
或者您可以创建搜索栏的出口,然后执行以下操作:-
@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)