0

在 iOS 15 中为 NavigationBar 尝试 Transperent,

它在低于 iOS 15 的版本中工作。

override func viewDidLoad() {
        // Clear the background image.
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        // Clear the shadow image.
        self.navigationController?.navigationBar.shadowImage = UIImage()
        // Ensure the navigation bar is translucent.
        self.navigationController?.navigationBar.isTranslucent = true

        if #available(iOS 15, *) {
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.shadowImage = UIImage()
            appearance.backgroundColor = .clear
            UINavigationBar.appearance().standardAppearance = appearance
            UINavigationBar.appearance().scrollEdgeAppearance = appearance
        }
}

如何使导航栏透明 iOS 15。 在此处输入图像描述

4

1 回答 1

1

如果你想要一个透明的导航栏.. 改变这一行:

appearance.configureWithOpaqueBackground()

至:

appearance.configureWithTransparentBackground()
于 2021-11-13T11:40:07.707 回答