HurkNburkS HurkNburkS - 4 months ago 56
iOS Question

Hide UISearchBar clear text button

I would like to know how to hide or not display the

UISearchBar
cross that appears in the
textField
fo the
UISearchBar


I have tried using this

filterSearchBar.showsCancelButton = NO;


however this is an acutal cancel button not the small grey cross, so I would like to know if there is an equivilant for the small grey button that shows in the
UISearchBar
.

any help would be appreciated.

Answer

You need to get the textField of the Search Bar:

UITextField *textField = [searchBar valueForKey:@"_searchField"];
textField.clearButtonMode = UITextFieldViewModeNever;

hope this help! =)