开发者

clear button in UISearchBar

开发者 https://www.devze.com 2023-03-19 20:00 出处:网络
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.

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;


 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号