Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove navigation bar border/shadow? [duplicate]

Tags:

ios

swift

So I have a navigation bar and it has a horizontal line that I'd like to remove.

Screenshot

I have removed the nav bar color from the screenshot to make the line more apparent.

I have tried setting the shadow image property of the navigation bar to a blank png (1x1 pixel pngs for 1x, 2x and 3x), but there's no effect.

like image 558
TimSim Avatar asked Mar 16 '16 12:03

TimSim


People also ask

How to remove border in navigationbar in Swift?

How to remove border in navigationBar in swift? To remove the border from a navigation bar in swift, we just need to add a few lines of code. Let’s see how the navigation bar looks when we run it without changing anything. Now let’s try to hide the line/ border shown in the above result.

How do I remove the border around a tab bar?

This property is commonly used to change the styles of the tab bar, for example, by applying the backgroundColor styles' property. To remove the border, add the tabBarOptions prop and inside it, add a style property called borderTopWidth with a value 0.

How do I hide the shadow image in the navigation bar?

The navigation bar has two things that give it the default view of a grey shadow along with bottom line as shown above. One is the background image, and the other is the shadow image. First, we’ll hide the shadow image, by setting it to empty image and see how it looks.

How to remove the bottom border of the uinavigationbar?

The UINavigationBar bottom border is an 1px shadow. According to the documentation to remove it you have to provide UIImage. But we’re going to create an empty UIImage.


2 Answers

Those two lines of code always do the trick for me :

 navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    navigationController?.navigationBar.shadowImage = UIImage()
like image 158
FruitAddict Avatar answered Oct 20 '22 20:10

FruitAddict


If you want to do it globally you can do:

UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
like image 29
Kubba Avatar answered Oct 20 '22 21:10

Kubba