如何更改背景颜色(而不是搜索栏文本字段)
我还如何增加状态栏和搜索栏之间的距离?看起来太近了。
我已经尝试过了,但是没有按预期工作:
func configureSearchController ()
{
searchController = UISearchController(searchResultsController: resultsController)
searchController.searchResultsUpdater = self
searchController.searchBar.layer.borderWidth = 0;
//searchController.searchBar.searchBarStyle = .minimal
searchController.searchBar.barTintColor = UIColor.searchBarBackgroundGrey()
for subView in searchController.searchBar.subviews {
for subViewOne in subView.subviews {
if subViewOne is UITextField {
subViewOne.backgroundColor = UIColor.searchBarTextFieldGrey()
break
}
}
}
}
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
searchBar.barTintColor = UIColor.white
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.barTintColor = UIColor.searchBarBackgroundGrey()
}
答案 0 :(得分:0)
您需要在viewDidLoad()
方法中设置搜索栏的委托:
searchController.searchBar.delegate = self