[英]hide separator line of navigation bar and keep the status bar the same color as the nav bar
I call 我打电话
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
in viewDidLoad. 在viewDidLoad中。
The separator line below the navigation bar disappears fine. 导航栏下方的分隔线消失得很好。 The problem is, the status bar turns white.
问题是状态栏变成白色。 I want it to stay the same color as the navigation bar.
我希望它保持与导航栏相同的颜色。
if just 如果只是
self.navigationController?.navigationBar.shadowImage = UIImage()
in viewDidLoad, looks like this: 在viewDidLoad中,如下所示:
below the nav bar I have a view the exact same colour as the nav bar. 在导航栏下方,我可以看到与导航栏完全相同的颜色。 I want this blended into one so it looks like the view below the nav bar is part of the nav bar.
我希望将其融合为一体,以便使其看起来像导航栏下方的视图是导航栏的一部分。
It is working for me. 它为我工作。 Can u check this answer.
你能检查一下这个答案吗?
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.blue
self.view.backgroundColor = UIColor.blue
// Add your colour
Your statusbar become white after you call self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
, because your viewController.extendedLayoutIncludesOpaqueBars
is NO
, so when you set a opaque background image for the navigationBar, the navigationBar's background will not start from 0
but from 20
, and nothing behind the statusbar, and statusbar showing as white. 在您调用
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
,状态栏将变为白色,因为您的viewController.extendedLayoutIncludesOpaqueBars
为NO
,因此,当您为navigationBar设置不透明的背景图像时,navigationBar的背景不会从0
开始,而是从20
开始,并且状态栏后面没有任何内容,并且状态栏显示为白色。
So you must call viewController.extendedLayoutIncludesOpaqueBars = YES
to avoid the white statusbar. 因此,您必须调用
viewController.extendedLayoutIncludesOpaqueBars = YES
以避免出现白色状态栏。
Custom shadowImage only work if you set a custom background image for the UINavigationBar
. 自定义shadowImage仅在为
UINavigationBar
设置自定义背景图像时才有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.