UIDocumentPickerViewController Navigation Bar Button Color

My application uses a red navigation bar (2) with white buttons and texts. When I use the system contact (3), the status bar is red. When I use the document picker (1) UIDocumentPickerViewController , then the navigation bar is white. How to change the color of the navigation bar or text?

When I use the following code, it works, but it also changes the navigation bar.

 UINavigationBar.appearance().tintColor = .red 

thanks for the 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

+5
source share
3 answers

Use setTitleTextAttributes

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

see my answer here

+2
source

This is the only solution found:

  UINavigationBar.appearance().tintColor = ... some color _viewController?.present(documentPicker, animated: true) 

As far as I know, it is impossible to set the color of the color only the color of the tint (text color). To preserve the hue color for the rest of your project, I reset it to the viewWillAppear of the main view controller.

+1
source

how do you ask "change color of navigation bar or text?" I don’t have a solution for the change navigation bar, it always returns nil

 self.present(documentPicker, animated: true,completion: { if documentPicker.navigationController?.navigationBar != nil{ documentPicker.navigationController?.navigationBar.barTintColor = .red } }) 

but if you agree to change only the text

it works for me

 self.present(documentPicker, animated: true,completion: { documentPicker.view.tintColor = .red }) 

I understand that this may not be optimal, but none of the solutions I'm trying to work for me

0
source

Source: https://habr.com/ru/post/1272036/


All Articles