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"
Wanted to add the Swift version of Serhii's answer. I created a
UIBarExtension.swift
with the following:I know this is an old thread, but I found a solution that works really well:
Subclass UINavigationBar. In your UINavigationBar subclass, override didAddSubview with the following code:
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!
The problem with setting a background image is it removes blurring. You can remove it without setting a background image. See my answer here.
If you just want to use a solid navigation bar color and have set this up in your storyboard, use this code in your
AppDelegate
class to remove the 1 pixel border via the appearance proxy:Try this:
Below image has the explanation (iOS7 NavigationBar):
And check this SO question: iOS7 - Change UINavigationBar border color