首页 > 解决方案 > UINavigationController 与 ViewController 相同的颜色

问题描述

在 Swift 4.0 中,我尝试为 UINavigationBar 应用与我的 viewController 颜色相同的颜色,简而言之,我想要透明的 Navigationbar,我尝试了所有选项,但仍然无法看到 Navigationbar 和 viewController 相同的颜色。(见附图)

self.navigationBar.backgroundColor = backGroundColor
self.navigationBar.barTintColor = backGroundColor
self.view.backgroundColor = backGroundColor

在此处输入图像描述

我知道如果我使用

self.navigationBar.setBackgroundImage(UIImage(), for: .default)
isTranslucent = false 

它将使背景透明,但当它滚动到顶部时,tableview 列表可能会在导航栏中可见,我不想要它。

还有其他选择吗?当 tableview 滚动到顶部时,导航栏应该是透明的,并且 tablview 列表在导航栏中不应该是可见的。

感谢你的帮助。

标签: iosuinavigationcontrolleruinavigationbar

解决方案


在应用一些效果后,您必须以看起来与您想要的颜色相同的方式设置颜色,您可以通过使用根据原始颜色计算的新值UINavigationBar更改背景颜色来实现此目的。UINavigationBar

您可以使用以下链接获取该值: http ://htmlpreview.github.io/?https://github.com/tparry/Miscellaneous/blob/master/UINavigationBar_UIColor_calculator.html

通过这样做,您可以使您的Translucent属性保持真实并获得您想要的相同结果。


推荐阅读