Search code examples
iosuinavigationbarios11

UIDocumentPickerViewController navigation bar buttons color


My app is using red navigation (2) bar with white buttons and texts. When I use system contact picker (3) the status bar is red. When I use documents picker (1) UIDocumentPickerViewController then navigation bar is white. How I can change color of navigation bar or text?

When I use code bellow, it works but it change my navigation bar too.

UINavigationBar.appearance().tintColor = .red

thanks for help

code:

func open() {
        UINavigationBar.appearance().barTintColor = .green
        let documentsController = UIDocumentPickerViewController(documentTypes: makeDocumentTypesList(), in: .import)
        documentsController.delegate = self
        viewControllerProvider.getViewController().present(documentsController, animated: true, completion: nil)
    }

navigation bar


Solution

  • You can just reset the appearance for UIDocumentPickerViewController only by putting this code somewhere in your application:didFinishLaunchingWithOptions: function and the bar buttons will return to their original blue or you can set any other color of your choice. The bar color, on the other hand is not customizable.

    if #available(iOS 11.0, *) {
        UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
    }