Error Regarding Navigation Bar Customization

Hey @Huzaifa!

I can see what you wanted to achieve here. Changing the navigation bar’s translucency or barTintColor directly no longer works ever since iOS 15.

The iOS 13 SDK introduced an appearance settings class for the UINavigationBar called UINavigationBarAppearance.

In iOS 15, by default the appearance settings applied produces a transparent background to all navigation bar styles. You can read more about it from Apple’s technical notes for the UINavigationBar.

If you’re targeting a minimum target of iOS 15 and later, you can try using:

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let newNavBarAppearance = UINavigationBarAppearance()

        // Configuring an opaque background
        newNavBarAppearance.configureWithOpaqueBackground()
        // or you can use:
        // newNavBarAppearance.configureWithTransparentBackground()
        // when you wanted a configuration with a transparent background
        
        // Navigation bar's background color
        newNavBarAppearance.backgroundColor = .purple
        
        // Navigation bar's title foreground color
        newNavBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
        
        // Apply the appearance to different styles:
        navigationController?.navigationBar.scrollEdgeAppearance = newNavBarAppearance
        navigationController?.navigationBar.compactAppearance = newNavBarAppearance
        navigationController?.navigationBar.standardAppearance = newNavBarAppearance
        if #available(iOS 15.0, *) {
            navigationController?.navigationBar.compactScrollEdgeAppearance = newNavBarAppearance
        }
    }

Hope it helps!