iOS Change the title of cancel button in UISearchBar

前端 未结 13 1894
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 10:35

I wish to change the title of the cancel button in iOS. I have been using this previously:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayCon         


        
13条回答
  •  伪装坚强ぢ
    2020-12-28 11:03

    @Nitin Gohel Like so?

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
      self.searchDisplayController.searchBar.showsCancelButton = YES;
      UIButton *cancelButton = nil;
      for (UIView *subView in self.searchDisplayController.searchBar.subviews) {
         if ([subView isKindOfClass:NSClassFromString(@"UIButton")]) {
             cancelButton = (UIButton*)subView;
    
             [cancelButton setTitle:@"Annuller" forState:UIControlStateNormal];
         }
     }
    
    }
    

提交回复
热议问题