iOS Change the title of cancel button in UISearchBar

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

    simply do this code for it:-

    - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
    {
        /* when user start editing in serchbar this method will display cancel button and disable the autocorrection functionality */
    
        srcbar.showsCancelButton = YES;
    
        for (UIView *subView in searchBar.subviews) {
            if ([subView isKindOfClass:[UIButton class]]) {
               UIButton *cancelButton = (UIButton*)subView;
    
                [cancelButton setTitle:@"hi" forState:UIControlStateNormal];
            }
        }
        srcbar.autocorrectionType = UITextAutocorrectionTypeNo;
    
    }
    

    Not test in iOS7 but this working fine in iOS6 hope this working for you.

    OUTPUT IS:-

    enter image description here

提交回复
热议问题