I'm experiencing an odd behavior with the UISearchBar in iOS. My search bar was working fine:
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:
When scrolling the results table view, the underlying content is visible in that gap:
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:
Is there something I can do to prevent it from showing that discolored gap and still have globally opaque navigation bars?
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.
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