在swift中删除navigationBar中的边框 [英] Remove border in navigationBar in swift

查看:107
本文介绍了在swift中删除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: "")

因为你没有图像wi没有名字, UIImage(名称:)返回 nil ,这意味着默认行为开始:

Since you don't have an image with no name, UIImage(named: "") returns nil, which means the default behavior kicks in:


当非零时,显示自定义阴影图像而不是默认阴影图像。要显示自定义阴影,还必须使用-setBackgroundImage设置自定义背景图像:forBarMetrics :(如果使用默认背景图像,将使用默认阴影图像。)

When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be shown, a custom background image must also be set with -setBackgroundImage:forBarMetrics: (if the default background image is used, the default shadow image will be used).

你需要一个真正的空图像,所以只需用 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()

这篇关于在swift中删除navigationBar中的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆