'How to change the navigationBar color in UIDocumentInteractionController in iOS 15?

Here's what I have tried so far:

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController
{
    navigationController?.navigationBar.barTintColor = UIColor.black
    navigationController?.navigationBar.backgroundColor = UIColor.black
    navigationController?.navigationBar.tintColor = UIColor.white
    navigationController?.navigationBar.isTranslucent = false

    return self.navigationController ?? self
}

I have tried it using UINavigationBar.appearance().barTintColor = UIColor.black, still it didn't work.

At best the navBar changes to translucent color of the previous ViewController.

Blockquote



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source