2012-12-10 42 views
2

我正在使用以下方法來停止取消按鈕項目在搜索欄中顯示。我有一個自定義UIButton,我想用它來代替。如何覆蓋UISearchBar中的取消按鈕

問題是,目前內置的取消按鈕仍然顯示出來。

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller 
{ 
    controller.searchBar.showsCancelButton = NO; 
} 

感謝您的幫助

+0

你programaticaly或通過添加搜索欄取消按鈕XIB? –

回答

3

您可以隱藏你使用這個

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 
{ 
    [searchBar setShowsCancelButton:NO animated:YES]; 
} 
0
for (UIView *possibleButton in searchBar.subviews) 
{ 
    if ([possibleButton isKindOfClass:[UIButton class]]) 
    { 
     UIButton *cancelButton = (UIButton*)possibleButton; 
     cancelButton.enabled = YES; 
     break; 
    }  
} 

一個通過這個鏈接UISearchBar disable auto disable of cancel button

相關問題