【问题标题】:Transparent navigation bar iOS 13透明导航栏 iOS 13
【发布时间】:2020-09-19 14:03:40
【问题描述】:

iOS 13 无法创建透明 NavigationBar。

我有自定义 UINavigationBar,我在其中配置 UINavigationBarAppearance

override init(frame: CGRect) {
    super.init(frame: frame)
    self.configure()
}

required init?(coder: NSCoder) {
    super.init(coder: coder)
    self.configure()
}

配置代码:

let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.shadowColor = .clear
appearance.backgroundColor = .clear

并将其设置为:

self.compactAppearance = appearance
self.standardAppearance = appearance
self.scrollEdgeAppearance = appearance

结果我得到了这个:

预期结果:NavigationBar 应该是透明的

【问题讨论】:

标签: ios swift uinavigationbar ios13 uinavigationbarappearance


【解决方案1】:

为我工作:

self.compactAppearance = appearance
self.standardAppearance = appearance
self.scrollEdgeAppearance = appearance
self.backgroundColor = appearance.backgroundColor

【讨论】:

    【解决方案2】:

    修改外观代码为:-

    let appearance = UINavigationBarAppearance()
    appearance.configureWithTransparentBackground()
    appearance.shadowColor = .clear
    appearance.backgroundColor = .clear
    appearance.backgroundImage = nil
    appearance.shadowImage = nil
    

    【讨论】:

    • 您可以剪切最后 4 行。它们与 configureWithTransparentBackground 相同,您已经说过了。
    猜你喜欢
    • 1970-01-01
    • 2018-03-05
    • 2016-12-20
    • 2014-11-08
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    相关资源
    最近更新 更多