You can't achieve what you are looking for from storyboard. You must programmatically add the search bar to the UINavigationBar
's navigationItem
. Like so,
let searchBar = UISearchBar() // Your Search bar
self.navigationController.navigationItem.titleView = searchBar
The only other thing you might consider is that this shouldnt be a UINavigationBar
but instead a UIView
with a UISearchBar
subview. That you could put together in storyboard.
EDIT (answer for comment)
"and the cancel button how can I add it?"
This you can easily add. Something like this:
let cancelButton = UIBarButtonItem(title: "Cancel", style: .done, target: self, action: #selector(cancelButtonTapped))
self.navigationController.navigationItem.rightBarButtonItem = cancelButton
"can I hide my navigationBar in storyboard?"
Yes. Select the view controller in which you'd like to hide the UINavigationBar
, select the inspector pane, and for "Top Bar" choose "None".
