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)
|