ios - 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 列表在导航栏中不应该是可见的。
感谢你的帮助。
解决方案
在应用一些效果后,您必须以看起来与您想要的颜色相同的方式设置颜色,您可以通过使用根据原始颜色计算的新值UINavigationBar
更改背景颜色来实现此目的。UINavigationBar
您可以使用以下链接获取该值: http ://htmlpreview.github.io/?https://github.com/tparry/Miscellaneous/blob/master/UINavigationBar_UIColor_calculator.html
通过这样做,您可以使您的Translucent
属性保持真实并获得您想要的相同结果。
推荐阅读
- azure-data-explorer - 使用 Azure 数据资源管理器使用动态值汇总和透视数据集中的数据
- python - 检测变量并在设置脚本中获取其值
- laravel - 动态接收id和model
- postgresql - Nginx tcp 流反向代理
- c# - C# Directory.GetFolder 对文件夹进行排序并将它们设置为 List<> 而不会丢失内存并执行额外的排序操作
- python - Python cProfile/pstats 导致溢出?
- reactjs - 条件反应文本掩码渲染
- python - 返回与其元组的第二个元素中的最大值链接的字典键
- npm - Node-RED 输入/输出未显示
- cesium - 使用 Cesium.CallbackProperty 显示/隐藏实体