I have an app that sometimes needs its navigation bar to blend in with the content.
Does anyone know how to get rid of or to change color of this annoying little bar?
On the image below situation i have – i'm talking about this 1px height line below "Root View Controller"
Best Answer
For iOS 13:
Use the
.shadowColor
propertyFor instance:
For iOS 12 and below:
To do this, you should set a custom shadow image. But for the shadow image to be shown you also need to set a custom background image, quote from Apple's documentation:
So:
Above is the only "official" way to hide it. Unfortunately, it removes bar's translucency.
I don't want background image, just color##
You have those options:
Solid color, no translucency:
Create small background image filled with color and use it.
Use 'hacky' method described below. It will also keep bar translucent.
How to keep bar translucent?##
To keep translucency you need another approach, it looks like a hack but works well. The shadow we're trying to remove is a hairline
UIImageView
somewhere underUINavigationBar
. We can find it and hide/show it when needed.Instructions below assume you need hairline hidden only in one controller of your
UINavigationController
hierarchy.Declare instance variable:
Add method which finds this shadow (hairline)
UIImageView:
Add/edit
viewWillAppear/viewWillDisappear
methods:The same method should also work for
UISearchBar
hairline, and (almost) anything else you need to hide :)Many thanks to @Leo Natan for the original idea!