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

后端 未结 15 1999
慢半拍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:36

    You also need to have the "searchBar setShowsCancelButton" before the procedure.

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        [theSearchBar setShowsCancelButton:YES animated:NO];
        for (UIView *subView in theSearchBar.subviews){
            if([subView isKindOfClass:[UIButton class]]){
                [(UIButton*)subView setTitle:@"Done" forState:UIControlStateNormal];
            }
        }
    }
    

    Note also: use UIButton to avoid problems with Apple!

提交回复
热议问题