I'm trying to change the colour of the clear button icon for my UISearchBar
using the following code:
let searchField = searchBar.value(forKey: "searchField") as? UITextField
if let clearButton = searchField?.value(forKey: "clearButton") as? UIButton {
clearButton.setImage(clearButton.imageView?.image?.withRenderingMode(.alwaysTemplate), for: .normal)
clearButton.tintColor = .white
}
This doesn't work if called in viewDidLoad
because the clear button isn't visible. How do I make this work?
Note: This is not related to the tinting of the cancel button or anything else as stated in the comments, just the clear button that looks like an x.