iOS8 Cannot hide cancel button on search bar in UISearchController

后端 未结 9 608
后悔当初
后悔当初 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:47

    Simply subclass UISearchController & UISearchBar.

    class NoCancelButtonSearchController: UISearchController {
        let noCancelButtonSearchBar = NoCancelButtonSearchBar()
        override var searchBar: UISearchBar { return noCancelButtonSearchBar }
    }
    
    class NoCancelButtonSearchBar: UISearchBar {
        override func setShowsCancelButton(_ showsCancelButton: Bool, animated: Bool) { /* void */ }
    }
    

提交回复
热议问题