Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gap above UISearchBar using UISearchController

I'm experiencing an odd behavior with the UISearchBar in iOS. My search bar was working fine:

Good UISearchBar

But when I set UINavigationBar.appearance().translucent = false in my ApplicationDelegate's didFinishLaunchingWithOptions to get the colors right in the Navigation Bar in my iOS app, the search bar gets a white section above it like this:

Broken UISearchBar

When scrolling the results table view, the underlying content is visible in that gap:

Broken UISearchBar translucent

The closest I've gotten to fixing it, was setting mySearchResultsViewController.edgesForExtendedLayout = UIRectEdge.None, which stopped the translucent gap, but still doesn't have the right color:

Broken UISearchBar edgesForExtendedLayout None

Is there something I can do to prevent it from showing that discolored gap and still have globally opaque navigation bars?

like image 527
Albert Bori Avatar asked Aug 03 '15 21:08

Albert Bori


1 Answers

After much googling, I found the following answer buried in the search results: UISearchController doesn't work properly with a non-translucent UINavigationBar

Specifically, this snippet worked when I put it in the presenting view controller:

func viewDidLoad() {
    extendedLayoutIncludesOpaqueBars = true
}

So simple, yet difficult to guess.

like image 63
Albert Bori Avatar answered Nov 05 '22 09:11

Albert Bori