1

无法创建透明 NavigationBar iOS 13。

我有自定义 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 应该是透明的

4

2 回答 2

3

将外观代码修改为:-

let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
appearance.shadowColor = .clear
appearance.backgroundColor = .clear
appearance.backgroundImage = nil
appearance.shadowImage = nil
于 2020-06-01T11:01:14.927 回答
1

为我工作:

self.compactAppearance = appearance
self.standardAppearance = appearance
self.scrollEdgeAppearance = appearance
self.backgroundColor = appearance.backgroundColor
于 2020-06-01T22:20:37.570 回答