iosswiftuikitphpickerviewcontroller

How to set nav button colors to black in iphone limited access library picker?


screenshot picker view

I'm having trouble customizing the nav button colors in PHPickerViewController when it is shown with limited photo library access on iOS. The navigation bar buttons ("Cancel" and "Done") are appearing in white on a white background, which makes them invisible. I want them to appear in black for better visibility.

What I have tried:

  1. Setting Global UINavigationBar Appearance in AppDelegate:
UINavigationBar.appearance().tintColor = UIColor.black
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.shadowColor = .clear
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
  1. Customizing PHPickerViewController Directly:
@objc func openPHPicker() {
    if #available(iOS 14.0, *) {
        var configuration = PHPickerConfiguration()
        configuration.selectionLimit = 4
        configuration.filter = .images

        let picker = PHPickerViewController(configuration: configuration)
        picker.navigationController?.navigationBar.tintColor = .black
        picker.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]
        picker.delegate = self
        self.present(picker, animated: true, completion: nil)
    }
}

Despite trying both approaches, the buttons still appear in white on the limited access library view. I've noticed that other apps (like Instagram) manage to display these buttons in black, so I assume there must be a way to enforce this styling, but I can't figure out how.


Solution

  • I don't know if this is a valid aproach or not, but you can try change tintColor of PHPickerViewController:

    picker.view.tintColor = .black