So I have a navigation bar and it has a horizontal line that I'd like to remove.
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.
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.
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.
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.
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.
Those two lines of code always do the trick for me :
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationController?.navigationBar.shadowImage = UIImage()
If you want to do it globally you can do:
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
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