iOS Development

ios – UINavigationBar background coloration not altering for a particular view

Spread the love


I’ve a worldwide setting initially of the app that makes the navigation bar white with black buttons like this:

        if #out there(iOS 13.0, *) {
            let look = UINavigationBarAppearance()
            look.configureWithTransparentBackground()
            look.backgroundColor = UIColor.white

            let buttonAppearance = UIBarButtonItemAppearance()
            buttonAppearance.regular.titleTextAttributes = [.foregroundColor: UIColor.black]
            look.buttonAppearance = buttonAppearance
            look.doneButtonAppearance = buttonAppearance

            UINavigationBar.look().standardAppearance = look
            UINavigationBar.look().scrollEdgeAppearance = look
            UINavigationBar.look().compactAppearance = look
            UINavigationBar.look().tintColor = UIColor.black
            UINavigationBar.look().shadowImage = UIImage()
            UINavigationBar.look().setBackgroundImage(UIImage(), for: .default)
        } else {
            UINavigationBar.look().backgroundColor = UIColor.white
            UINavigationBar.look().shadowImage = UIImage()
            UINavigationBar.look().setBackgroundImage(UIImage(), for: .default)
        }

It really works effectively, now the problem I’ve one particular viewcontroller the place I need the navigation bar to be one other coloration however nothing appears to work.
I attempted the entire following in viewDidLoad :

            let look = UINavigationBarAppearance()
            look.configureWithTransparentBackground()
            look.backgroundColor = .purple //1

            let buttonAppearance = UIBarButtonItemAppearance()
            buttonAppearance.regular.titleTextAttributes = [.foregroundColor: UIColor.white]
            look.buttonAppearance = buttonAppearance
            look.doneButtonAppearance = buttonAppearance

            UINavigationBar.look().standardAppearance = look
            UINavigationBar.look().scrollEdgeAppearance = look
            UINavigationBar.look().compactAppearance = look

self.navigationController?.navigationBar.barTintColor = .purple //2

self.navigationController?.navigationBar.backgroundColor = .purple //3

I checked the assorted questions associated to navigationbar colours however all of them appears to recommend the identical issues that do not work.

Utilizing Xcode 15.2 iOS 17.2

Leave a Reply

Your email address will not be published. Required fields are marked *