iOS Change the title of cancel button in UISearchBar

前端 未结 13 1801
隐瞒了意图╮
隐瞒了意图╮ 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

    Refer to @Salih's solution above, I used this code and work perfect! Just call the method setupAppearance in AppDelegate.m when app launching.

    - (void)setupAppearance
    {
       id appearance = nil;
    
       if (IOS9_OR_LATER) {
           appearance = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]];
       } else {
           appearance = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
       }
    
       [appearance setTitle:@"CANCEL"];
    }
    

提交回复
热议问题