我在导航栏中嵌入了 SearchController .如何将 UITextField 颜色更改为将搜索字符串保存为白色的颜色.?
i have embedded SearchController in navigation bar . How to Change UITextField Color The one which Holds search String To White .?
这将帮助您实现您想要的.只需在此代码中应用您的颜色组合并查看.
This will help you to achieve, what you want. Just apply your color combination in this code and see.
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
}
结果:
这篇关于如何更改搜索控制器中的 uitextfield 颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!