UIDocumentInteractionController doesn't respect UINavigationBar's barTintColor appearance in iOS 11

Viewed 866

I have a sample project that sets the bar tint color when the app launches:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UINavigationBar.appearance().barTintColor = UIColor.red
    return true
}

It has 1 view controller (inside of a UINavigationController), with this code in it:

@IBAction func launchDocument(_ sender: Any) {
    if let url = Bundle.main.url(forResource: "example", withExtension: "pdf") {            
        let controller = UIDocumentInteractionController(url: url)
        controller.delegate = self
        controller.presentPreview(animated: false)
    }
}

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self
}

In iOS 10, both the main view controller and the UIDocumentInteractionController have red navigation bars. In iOS 11, the UIDocumentInteractionController isn't red. Is this a bug with iOS 11? Or is there another way to do this?

P.S. - I know that I can return self.navigationController in the delegate, but I need the UIDocumentInteractionController to have a "Done" button, not a "Back" button

3 Answers

Same issue on iOS 11 public release, from my testing, so far it looks only follows [setBarStyle]

 [[UINavigationBar appearance] setBarStyle: UIBarStyleBlack];

Same issue. But i realized it's about barTintColor. setBackgroundImage works for me.

  • Create a small image with your background color and add this line:

     UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "nav_bg")?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 15, 0, 15), resizingMode: .stretch), for: .default)
    
Related