gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:30:30 26 4
gpt4 key购买 nike

我正在使用 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()
}

最佳答案

使用这个

self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 
0.2933186293, green: 0.8084665537, blue: 0.8478894234, alpha: 1)

关于swift - 如何在 Swift 5 中以编程方式更改导航栏的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59280520/

26 4 0