I am working on implementing accessibility for a screen in IOS. The screen contains UISearchBar and I am able to scale/change the height of the search bar and the textfield inside it and the textfield's text font based on the system font changes in accessibility settings. However, I am not able to change the width and height of the default clear button that appears when the user types in the search. I want to change the height and width of the clear button based on the changes in the system font size. I tried the below code but it is not modifying the height and width of clear button. I want to have same width and height for clear button and hence using the "newHeight" to set height and width. Any pointers on how can I modify the height and width of the default clear button in UISearchBar.
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
if let textField = searchBar.textField, let clearButton = textField.value(forKey: "_clearButton") as? UIButton {
let newHeight = UIFontMetrics(forTextStyle: .body).scaledValue(for: clearButton.frame.height)
clearButton.frame.size = CGSize(width: newHeight, height: newHeight)
}
}
FYI, I have created an extension method on UISearchBar to retrieve the textField. So, you can assume that searchBar.textField returns textfiield.