0%

删除UISearchBar背景,设置空也可以点击搜索

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
func removeSearchBarBgView(frome view: UIView) {
for sv in view.subviews {
// 去除背景
if let className = NSClassFromString("UISearchBarBackground") {
if sv.isKind(of: className) {
sv.removeFromSuperview()
continue
}
}
// 设置空字符也可以点击搜索
if let t = sv as? UITextField {
t.enablesReturnKeyAutomatically = false
}
removeSearchBarBgView(frome: sv)
}
}
searchBar = UISearchBar()
searchBar.placeholder = "搜索"
searchBar.backgroundColor = UIColor.clear
searchBar.delegate = self
searchBar.tintColor = UIColor.paOrange
removeSearchBarBgView(frome: searchBar)