Hiding Cancel button on search bar in UISearchController

前端 未结 6 868
离开以前
离开以前 2020-12-07 02:08

I\'m trying to hide the Cancel button of the search bar in the UISearchController, but unfortunately setting the following in viewDidLoad() does not work:

ov         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 02:28

    The same answer as given by @Griffith and @Abhinav but using extension:

    extension UISearchBar {
        override open func layoutSubviews() {
            super.layoutSubviews()
            setShowsCancelButton(false, animated: false)
        }
    }
    

    This code is from Swift 4.

提交回复
热议问题