Reputation: 7921
I have my UISearchBar
placed in a navigation bar. When I tap on the bar, it expands itself and shows the cancel button. If you type something in the field and then you tap on "Search" on the keyboard, it dismiss the keyboard showing you the results. But in this moment I'm having a big problem : the cancel button is now disabled (greyed out) and if I tap on it, first the keyboard is opened and then I can tap again on the Cancel to exit from the search. Is it possible to keep the Cancel button active always so I can directly tap on it to exit from the search?
Upvotes: 1
Views: 1010
Reputation: 3677
searchBar.showsCancelButton = YES;
You can create another custom button on UISearchBar.
for (UIView *subView in searchBar.subviews) {
if([subView isKindOfClass:[UIButton class]]) {
UIButton *cancelButton = (UIButton *)[searchBar.subviews lastObject];
//Make changes to the cancelButton here
[cancelButton setEnabled:YES];
}
}
Upvotes: 1