【问题标题】:Remove Gradient and make Transparent navigation bar in ios 15在 ios 15 中删除渐变并制作透明导航栏
【发布时间】:2022-01-03 12:28:28
【问题描述】:

我已尝试使用以下代码从导航中删除渐变并为 ios 15 制作透明导航栏,但它并没有在相同的情况下工作,而在较低版本中它工作得非常好。

if let bar =  self.navigationController?.navigationBar {
            if #available(iOS 15.0, *) {
                let navigationBarAppearance = UINavigationBarAppearance()
                navigationBarAppearance.configureWithTransparentBackground()
                navigationBarAppearance.shadowImage = UIImage()
                self.title = ""
                navigationBarAppearance.backgroundImage = UIImage()
                navigationBarAppearance.backgroundColor = .clear
                UINavigationBar.appearance().isTranslucent = true
                UINavigationBar.appearance().standardAppearance = navigationBarAppearance
                UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance   
        
            } else {
                bar.setBackgroundImage(FCUtil.getImageWithColor(color: UIColor.clear, size: bar.frame.size), for: UIBarMetrics.default)
                bar.isTranslucent = true
                bar.shadowImage = UIImage()
                self.title = ""
            }
        }

如果我错过了什么,请给我建议。

【问题讨论】:

标签: swift gradient transparent navigationbar ios15


【解决方案1】:

您的代码的唯一问题是时间。您运行代码太晚了。更改导航栏appearance() 无法更改已存在的导航栏。

相反,只需直接更改bar 本身:

bar.standardAppearance = navigationBarAppearance
bar.scrollEdgeAppearance = navigationBarAppearance   

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 2021-12-24
    • 1970-01-01
    • 2021-11-21
    • 2021-12-02
    • 2014-01-29
    • 2020-09-19
    • 2018-03-05
    • 2016-12-20
    相关资源
    最近更新 更多