我正在尝试将搜索栏的灰色区域(矩形区域)颜色更改为其他颜色(橙色)。我尝试使用searchBar.barTintColor =但这只是改变取消按钮的颜色而不是灰色区域。 编辑
class usersVC: UITableViewController, UISearchBarDelegate {
// declare searchBar
var searchBar = UISearchBar()
// default function
override func viewDidLoad() {
super.viewDidLoad()
// implement search bar
searchBar.delegate = self
searchBar.showsCancelButton = true
searchBar.sizeToFit()
searchBar.placeholder = "Search"
searchBar.frame.size.width = self.view.frame.size.width - 30
let searchItem = UIBarButtonItem(customView: searchBar)
self.navigationItem.leftBarButtonItem = searchItem
}