简体   繁体   English

如何删除 iOS 13 中出现的导航栏背景?

[英]How I can remove navigation bar background with appearance in the iOS 13?

I am tried to remove the navigation bar background in iOS 13 in the if's statements with #available.我试图在#available的if语句中删除iOS 13中的导航栏背景。 I know the original code to remove the navigation bar background for iOS 12 and older iOS in the else's statements.我知道在 else 的语句中删除 iOS 12 和旧版 iOS 的导航栏背景的原始代码。 However, Apple did announce a new system called Appearance in anywhere to support that new iOS 13 system.但是,Apple 确实在任何地方宣布了一个名为Appearance的新系统,以支持新的 iOS 13 系统。

    let app = UINavigationBarAppearance()

    let navigationBar = self.navigationController?.navigationBar

    app.configureWithOpaqueBackground()
    app.shadowImage = UIImage()


    self.navigationController?.navigationBar.scrollEdgeAppearance = app

    navigationBar!.standardAppearance = app
    navigationBar!.scrollEdgeAppearance = app

I believe this configureWithOpaqueBackground() allows us to remove the navigation bar background, But I test on iOS 13.1 simulator appear black navigation bar background.我相信这个 configureWithOpaqueBackground() 允许我们移除导航栏背景,但是我在 iOS 13.1 模拟器上测试出现黑色导航栏背景。 I know what caused it.我知道是什么原因造成的。

     app.configureWithOpaqueBackground()
     app.titleTextAttributes = [.foregroundColor: UIColor.white]
     app.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
     app.backgroundColor = #colorLiteral(red: 0.1603881121, green: 0.1677560508, blue: 0.2133775949, alpha: 1)

That code allows us to put the custom color on the black background.该代码允许我们将自定义颜色放在黑色背景上。 I ready to add that code in the viewWillDisappear's statements to restore the navigation bar background to normal color background before self.navigationController?.navigationBar.scrollEdgeAppearance = app with remove app.configureWithOpaqueBackground() and app.shadowImage = UIImage() .我准备在 viewWillDisappear 的语句中添加该代码,以在self.navigationController?.navigationBar.scrollEdgeAppearance = app之前将导航栏背景恢复为正常颜色背景,并删除app.configureWithOpaqueBackground()app.shadowImage = UIImage() Now, I need to create the translucent navigation bar background in the viewWillAppear's statements, but it can't see any translucent background due to the black background still display.现在,我需要在 viewWillAppear 的语句中创建半透明的导航栏背景,但是由于仍然显示黑色背景,它看不到任何半透明的背景。

I really appreciate your help in resolving the problem: :)我非常感谢您在解决问题方面的帮助::)

If you want the navigation bar to become completely transparent:如果您希望导航栏变得完全透明:

    let app = UINavigationBarAppearance()
    app.configureWithTransparentBackground()
    self.navigationController?.navigationBar.standardAppearance = app
    self.navigationController?.navigationBar.scrollEdgeAppearance = app
    self.navigationController?.navigationBar.compactAppearance = app

Do not mess with the isTranslucent of the navigation bar.不要乱用导航栏的isTranslucent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM