如何覆盖UISearchBar中的取消button
我正在使用以下方法停止取消button项目在search栏中显示。 我有一个自定义的UIButton
,我想用它来代替。
问题是,目前内置的取消button仍然显示出来。
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller { controller.searchBar.showsCancelButton = NO; }
谢谢你的帮助
你可以用这个隐藏你的取消button
- (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; } }
一个通过这个链接UISearchBar禁用取消button的自动禁用