Search code examples
swiftios11uidocumentpickerviewcontroller

UIDocumentPicker navigation bar buttons are hidden at iOS 11


I notice a problem in my UIDocumentPicker's navigation bar at iOS 11 only, the done, cancel, or edit buttons are invisible, and when the user touch it it appears i.e. The color at normal state is white, even when changing the UINavigationBar.appearnce().tintColor, The color only changed on touch.

enter image description here enter image description here


Solution

  • Use CustomDocumentPickerViewController with black appearance for UINavigationBar and UIBarButtonItem

    import UIKit
    
    class CustomDocumentPickerViewController: UIDocumentPickerViewController {
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
    
            UINavigationBar.appearance().tintColor = UIColor.black
            UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.black], for: .normal)
        }
    
        override func viewWillDisappear(_ animated: Bool) {
    
            UINavigationBar.appearance().tintColor = UIColor.white // your color
            UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: .normal)
            super.viewWillDisappear(animated)
    
        }
    
    }