本文介绍了如何快速删除NavigationBar的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试删除NavigationBars边框,但是没有运气.经过研究,人们似乎告诉我们将shadowImage和BackgroundImage设置为nil,但这在我的情况下不起作用.
i've been trying to remove the navigationBars border without luck. I've researched and people seem to tell to set shadowImage and BackgroundImage to nil, but this does not work in my case.
我的代码
self.navigationController?.navigationBar.barTintColor = UIColor(rgba: "#4a5866")
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: ""), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage(named: "")
插图:
推荐答案
问题出在这两行:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: ""), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage(named: "")
由于没有没有名称的图像,因此UIImage(named: "")
返回nil
,这意味着将启动默认行为:
Since you don't have an image with no name, UIImage(named: "")
returns nil
, which means the default behavior kicks in:
您需要一个真正为空的图像,因此只需使用UIImage()
进行初始化:
You need a truly empty image, so just initialize with UIImage()
:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
这篇关于如何快速删除NavigationBar的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!