I\'m trying to change the background color of input field of UISearchBar.It\'s the rounded view where you input text to search, the default color is white. I would like to c
Take the extension worked in swift4:
extension UISearchBar {
var input : UITextField? {
return findInputInSubviews(of: self)
}
func findInputInSubviews(of view: UIView) -> UITextField? {
guard view.subviews.count > 0 else { return nil }
for v in view.subviews {
if v.isKind(of: UITextField.self) {
return v as? UITextField
}
let sv = findInputInSubviews(of: v)
if sv != nil { return sv }
}
return nil
}
}
usage:
searchBar?.input?.layer.borderColor = color.cgColor