12

I want to set the navigation bar background color of my DocumentPicker to be the same as the rest of my application.

    let filePicker = UIDocumentPickerViewController(documentTypes: ["public.content"], in: .import)
    filePicker.delegate = self
    filePicker.navigationController?.navigationBar.barTintColor = self.theme.navigationBarColor

    self.present(filePicker, animated: true, completion: nil)

doesn't work.

Other things I've tried:

Use UINavigationBar.appearance().backgroundColor = self.theme.navigationBarColor - doesn't work and looks too much like a workaround instead of a proper way if it works.

Edit: Right now our app is redesigned to use the primary color as navigation bar text color, and have the same background color as the DocumentPicker. Answers will still be appreciated.

Aguragorn
  • 585
  • 6
  • 14
  • 3
    Prior to iOS 11, you could do UINavigationBar.appearance().backgroundColor = UIColor.black and it worked fine. This seems to be a bug in iOS 11. I'm in a predicament where the nav bar is white, and the nav bar buttons (like "Cancel") are white, so they are invisible. – JohnnyC Nov 12 '17 at 20:03
  • 1
    @JohnnyC I'm having this issue as well. – Isuru Mar 18 '18 at 05:59
  • [UINavigationBar appearance].tintColor = [UIColor yourColor]; // for button title color and [UINavigationBar appearance].backgroundColor = [UIColor yourColor]; // for background color. Worked for me like a charm. I have this issue only iOS 14 version. – Ravi Mar 03 '21 at 12:21

1 Answers1

3

This will change the color of the text like "Cancel".

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blue], for: .normal)

and this will change the arrow back color.

UIButton.appearance().tintColor = UIColor.blue

Don't forget to set it back to your original colors after closing the picker if it required.

Developeder
  • 1,579
  • 18
  • 29