作者:好人木庄子mzz | 来源:互联网 | 2023-01-05 09:21
我已经在导航栏中嵌入了SearchController。如何更改UITextField的颜色将搜索字符串保留为White的颜色?
1> Krunal..:
这将帮助您实现所需的目标。只需在此代码中应用颜色组合即可查看。
if #available(iOS 11.0, *) {
let sc = UISearchController(searchResultsController: nil)
sc.delegate = self
let scb = sc.searchBar
scb.tintColor = UIColor.white
scb.barTintColor = UIColor.white
if let textfield = scb.value(forKey: "searchField") as? UITextField {
//textfield.textColor = // Set text color
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
if let navigatiOnbar= self.navigationController?.navigationBar {
navigationbar.barTintColor = UIColor.blue
}
navigationItem.searchCOntroller= sc
navigationItem.hidesSearchBarWhenScrolling = false
}
结果: