title: iOS 11 SearchBar in NavigationBar
body: <p>With iOS 11 Apple has redesigned the UISearchBar by making the corners rounder and the height bigger. Adding a UISearchBar to the navigationBar is pretty simple by just setting it as the titleView of the navigationItem using <code>navigationItem.titleView = searchBar</code>.</p>
  
  <p>However, in iOS 11 it does not seem to work anymore as expected.
  Have a look at the screens where we compare the same setup using iOS 10 and iOS 11</p>
  
  <p><strong>iOS 10</strong>
  <a href="https://i.stack.imgur.com/r70hL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/r70hL.png" alt="enter image description here"></a> </p>
  
  <p><strong>iOS 11</strong>
  <a href="https://i.stack.imgur.com/HCVEW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HCVEW.png" alt="enter image description here"></a></p>
  
  <p>You can clearly see that the SearchBar increases the size of the NavigationBar but the bar buttons do not get aligned correctly. Also the searchBar does not use the available space on the left anymore.</p>
  
  <p>Putting the searchBar into a wrapper view to get the cancel button on iPad as described here <a href="https://stackoverflow.com/questions/30474494/cancel-button-is-not-shown-in-uisearchbar">Cancel button is not shown in UISearchBar</a> also does not seem work anymore since the searchBar is then not visible at all.</p>
  
  <p>If anyone has similar issues or already knowns how to fix/improve this I would be very thankful.</p>
  
  <p>This was built using Xcode 9 Beta 4. Maybe future releases will fix this issue.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Since this does not get fixed we decided to use following solution.
  We added a new UIBarButtonItem to the NavBar which then presents a new ViewController where we only put a searchBar and nothing else into the NavBar which seems to work. Using the selected answer may be the best solution since Apple with iOS 11 wants us to use this new design even if it does not give us the result we originally wanted. Another way to possible solve this could be a custom SearchBar but this is another topic.</p>