Hide UISearchBar Cancel Button

后端 未结 11 870
夕颜
夕颜 2020-12-24 06:39

I have a UISearchDisplayController and UISearchBar hooked up to my ViewController via Outlets from my nib.

I\'d like to hide the cancel button so that the user never

11条回答
  •  庸人自扰
    2020-12-24 07:17

    If the cancel button shows up when editing the search field of the search bar you could do the following; subclass the search bar and have it implement the UITextFieldDelegateprotocol:

    @interface CustomAlignedSearchBar : UISearchBar
    

    Then implement textFieldDidBeginEditing: and do something like:

    - (void)textFieldDidBeginEditing:(UITextField *)textField{
        [self setShowsCancelButton:self.cancelButtonShown animated:NO];
    }
    

    This will make sure that the cancel button will not show up.

提交回复
热议问题