UIDocumentPicker navigation bar buttons are hidden at iOS 11
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.
UINavigationBar.appearnce().tintColor


UINavigationBar.appearance().tintColor = tintColor
I have the exact same problem! The buttons are not displayed but are working when tapped..
– franswa
Dec 17 '17 at 20:12
3 Answers
3
Use CustomDocumentPickerViewController with black appearance for UINavigationBar and UIBarButtonItem
appearance
UINavigationBar
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)
}
}
For unknown reason I figured out that if you make a subclass of UIDocumentPicker using Objective-C and set the [UINavigationBar appearance].tintColor = [UIColor black]; in viewWillAppear func, and reset it to your defaults in the viewWillDisappear, it works well.
Objective-C
[UINavigationBar appearance].tintColor = [UIColor black];
viewWillAppear
viewWillDisappear
But if you do the same steps using swift it wont.
swift
correct answer & its working...
– Gajendra K Chauhan
Feb 25 at 15:32
I'm not a big fan of setting the global appearance between viewWillAppear and viewWillDisappear. The appearance API should be used at application start only. You can just reset the appearance for UIDocumentPickerViewController only without subclassing by putting this code in application:didFinishLaunchingWithOptions: and the bar buttons will return the their original blue:
viewWillAppear
viewWillDisappear
UIDocumentPickerViewController
application:didFinishLaunchingWithOptions:
if #available(iOS 11.0, *) {
UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
UINavigationBar.appearance().tintColor = tintColorhave to work.– Vyacheslav
Nov 26 '17 at 13:22