ios 如何删除导航栏边框/阴影?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36035407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove navigation bar border/shadow?
提问by TimSim
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.
我尝试将导航栏的阴影图像属性设置为空白 png(1x、2x 和 3x 的 1x1 像素 png),但没有效果。
回答by FruitAddict
Those two lines of code always do the trick for me :
这两行代码总是对我有用:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationController?.navigationBar.shadowImage = UIImage()
回答by Kubba
If you want to do it globally you can do:
如果你想在全球范围内做到这一点,你可以这样做:
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)