Navneet Kaur
Navneet Kaur

Reputation: 359

How to change the background color of navigation bar programmatically in Swift 5?

I'am using Swift 5 and trying to change the color of navigation bar colour while performing pop action. I've used the code written below but it didn't worked for me

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()
}

Upvotes: 1

Views: 542

Answers (1)

Chaman Sharma
Chaman Sharma

Reputation: 636

Use this

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

Upvotes: 1

Related Questions