In iOS 11, we now use
self.navigationItem.searchController = self.searchController
to embed search bar in navigation item title view. This, however, pushes the other navigation items above the search bar, like this:
Without using custom containers or going back to the old way of setting search bar, is there any way we can keep the other navigation items on the same level as the search bar in iOS 11? Like this:
You can try to achieve this by changing the cancel button like this:
let searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.showsCancelButton = true
if let view = searchController.searchBar.subviews.first {
for subview in view.subviews {
if let myButton = subview as? UIButton {
// setup button
myButton.setTitle("", for: .normal)
let image = UIImage(named: "myImage")
myButton.setBackgroundImage(image, for: .normal)
}
}
}
navigationItem.searchController = searchController
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With