iOS Change the title of cancel button in UISearchBar

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

    It seems like "self.searchDisplayController.searchBar.subviews" just return the "searchBar" itself. I tried bellow, and it works!

    for (UIView *searBarView in [self.searchDisplayController.searchBar subviews])
    {
        for (UIView *subView in [searBarView subviews]) 
        {
            if ([subView isKindOfClass:[UIButton class]])
            {
                UIButton *cancleButton = (UIButton *)subView;
                [cancleButton setTitle:@"hi" forState:UIControlStateNormal];
            }
        }
    
    }
    

提交回复
热议问题