问题描述
我想使用以下代码更改嵌入在iOS 11的UISearchController中的searchBar
中的文本字段的背景颜色:
class ViewController: UIViewController {
private var searchController: UISearchController!
private var data: [String] = []
private var filtered: [String] = []
private var tableView = UITableView(frame: .zero,style: .plain)
override func viewDidLoad() {
super.viewDidLoad()
for i in 1...100 {
self.data.append("row \(i)")
}
self.filtered = data
let src = SearchResultController()
self.searchController = UISearchController(searchResultsController: src)
self.searchController.delegate = self
self.searchController.searchResultsUpdater = src
self.searchController.searchBar.textField?.subviews.first?.backgroundColor = UIColor(red:0.25,green:0.37,blue:0.53,alpha:1)
if #available(iOS 13.0,*) {
self.searchController.showsSearchResultsController = true
}
self.navigationItem.title = "Search"
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationItem.searchController = searchController
self.setupNavigationBar()
self.setupTableView()
definesPresentationContext = true
}
}
所以当我写这样的代码
self.searchController.searchBar.textField.backgroundColor = UIColor(red:0.25,alpha:1)
什么都没有改变。
我写的时候
self.searchController.searchBar.textField?.subviews.first?.backgroundColor = UIColor(red:0.25,alpha:1)
当我写这篇文章时。阿尔法= 0.5
self.searchController.searchBar.textField?.subviews.first?.backgroundColor = UIColor(red:0.25,alpha:0.5)
我有这个。这就是我想要的。
所以我的问题是我做错了什么?还有什么合适的方法来设置嵌入在UISearchController中的搜索栏中的文本文件的背景色?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)