How to change the default text of Cancel Button which appears in the UISearchBar +iPhone

后端 未结 15 1995
慢半拍i
慢半拍i 2020-12-01 03:04

I am developing an Application where I wanted to change the text of Search String in the SearchBar. I wanted to change the text of Cancel Button Also which appears next to t

15条回答
  •  借酒劲吻你
    2020-12-01 03:42

    if the SearchBar is in the navigationBar, the code will be different than the usual answer; You need to search for NavigationBar's subviews instead.

    -(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
    UINavigationBar * navigationBar =  self.navigationController.navigationBar;
    
    for (UIView *subView in navigationBar.subviews){
        if([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]){
            [(UIButton*)subView setTitle:@"İptal" forState:UIControlStateNormal];
        }
    }}
    

    and This work in iOS7+ , if you still can't set the title you should learn view debugging - This is how I solved this problem of mine.

    This brief tutorial outlines the key points of View-Debugging very well:

    http://www.raywenderlich.com/98356/view-debugging-in-xcode-6

提交回复
热议问题