如何在Swift 5中以编程方式更改导航栏的背景颜色?

问题描述 投票:0回答:1

我正在使用Swift 5,并在执行弹出动作时尝试更改导航栏颜色。我使用了下面编写的代码,但对我没有用

func changeRootToLogin()
{
    guard let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "OnboardingViewController") as? OnboardingViewController else {
        return
    }

    let navigationController = UINavigationController(rootViewController: rootVC)
    self.navigationController?.navigationBar.backgroundColor = #colorLiteral(red: 0.2933186293, green: 0.8084665537, blue: 0.8478894234, alpha: 1)
    self.navigationController?.navigationBar.isHidden = false
    UIApplication.shared.windows.first?.rootViewController = navigationController
    UIApplication.shared.windows.first?.makeKeyAndVisible()
}
swift uinavigationcontroller ios13 swift5
1个回答
0
投票

使用此

self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 
0.2933186293, green: 0.8084665537, blue: 0.8478894234, alpha: 1)
© www.soinside.com 2019 - 2024. All rights reserved.