Hi can I remove clear button (X button)present in UISearchBar?
I didn't find any delegate for that. There is one fo开发者_StackOverflow中文版r cancel button.
Thanks
You can not directly access the clearButton of UISearchBar. You have to loop through the subviews of the UISearchBar to find the UITextField, and set its clearButtonMode property to UITextFieldViewModeNever.
Note: This is not a permanent solution because this may not work in future if the implementation of UISearchBar changes by the subsequent iOS updates.
You need to get the textField of the Search Bar
UITextField *textField = [searchBar valueForKey:@"_searchField"];
textField.clearButtonMode = UITextFieldViewModeNever;
use in - searchBarTextDidBeginEditing method.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
UITextField *textField = [searchBar valueForKey:@"_searchField"];
textField.clearButtonMode = UITextFieldViewModeNever;
}
精彩评论