【发布时间】:2017-12-14 13:08:46
【问题描述】:
【问题讨论】:
-
您想将文本字段背景更改为绿色并搜索字符串白色
标签: ios swift uinavigationcontroller ios11 uisearchcontroller
【问题讨论】:
标签: ios swift uinavigationcontroller ios11 uisearchcontroller
这将帮助您实现您想要的。只需在此代码中应用您的颜色组合并查看。
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
}
结果:
【讨论】:
searchController.obscuresBackgroundDuringPresentation = false 设置此属性成功了。