【问题标题】:Changing Color of the Navigation Bar's Safe Area Swift UIKit更改导航栏安全区域的颜色 Swift UIKit
【发布时间】:2022-10-05 03:30:38
【问题描述】:

我遇到了一个问题。我希望整个导航栏(包括安全区域)的颜色发生变化,但安全区域的颜色根本不会改变(无论我对其进行什么更改)。

继承人

    navigationController?.navigationBar.isTranslucent = false
    navigationController?.navigationBar.backgroundColor = .green
    
    navigationItem.titleView = searchBar

我什至尝试更改导航栏:

  • barTintColor
  • tintColor

没有运气。

Current Navigation Bar Color

此视图控制器正在使用导航控制器从场景委托中呈现。

如果您需要任何其他信息,请告诉我。

【问题讨论】:

    标签: ios swift uikit programmatically


    【解决方案1】:

    在我的应用程序中,我找不到使用 SwiftUI 设置栏背景颜色的方法,因此我在应用程序场景的初始化时使用 UIKit 来设置颜色。希望这可以帮助

    extension SceneDelegate {
        private func uiSetup() {
            // Navigation bar Appearance
            UINavigationBar.appearance().barTintColor = UIColor(red: 22, green: 22, blue: 22)
        }
    }
    

    【讨论】:

    • 感谢您的回复!你在哪里调用这个函数?我在场景中尝试了 willConnectTo 功能但没有运气
    【解决方案2】:

    找到了解决方案:

    
        let appearance = UINavigationBarAppearance()
                appearance.configureWithOpaqueBackground()
                appearance.backgroundColor = .green
                navigationController?.navigationBar.standardAppearance = appearance
                navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
                
                navigationItem.titleView = searchBar
    

    我在配置导航栏的函数中输入了这个

    信用:https://developer.apple.com/forums/thread/682420

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2014-09-01
      • 2016-06-28
      • 2015-11-03
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      相关资源
      最近更新 更多