iOS8 Cannot hide cancel button on search bar in UISearchController

后端 未结 9 617
后悔当初
后悔当初 2021-01-01 12:26

My goal is to prevent the cancel button from appearing in a search bar in a UISearchController. I started with Apple\'s Table Search with UISearchController sample code and

9条回答
  •  暖寄归人
    2021-01-01 12:50

    I think there are three ways of achieving that:

    1. Override searchDisplayControllerDidBeginSearch and use the following code:

    searchController.searchBar.showsCancelButton = false

    1. Subclass UISearchBar and override the layoutSubviews to change that var when the system attempts to draw it.

    2. Register for keyboard notification UIKeyboardWillShowNotification and apply the code in point 1.

    Of course can always implement your search bar.

提交回复
热议问题