I am currently using the following method to stop the cancel button item from showing up in the search bar. I have a custom UIButton
that I would like to use instead.
The problem is that at the moment the built in cancel button is still showing up.
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.searchBar.showsCancelButton = NO;
}
thanks for any help
You can hide your cancel button using this
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
}
for (UIView *possibleButton in searchBar.subviews)
{
if ([possibleButton isKindOfClass:[UIButton class]])
{
UIButton *cancelButton = (UIButton*)possibleButton;
cancelButton.enabled = YES;
break;
}
}
one go through this link UISearchBar disable auto disable of cancel button
Swift
4.2, 4.0+ of Rajneesh071 answer
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
searchBar.setShowsCancelButton(false, animated: true)
}