我的应用程序使用带有白色按钮和文本的红色导航栏(2)栏.当我使用系统联系人选择器(3)时,状态栏为红色.当我使用文件选择器(1)UIDocumentPickerViewController然后导航栏是白色的.如何更改导航栏或文本的颜色?
当我使用下面的代码时,它可以工作,但它也改变了我的导航栏.
- UINavigationBar.appearance().tintColor = .red
感谢帮助
码:
- func open() {
- UINavigationBar.appearance().barTintColor = .green
- let documentsController = UIDocumentPickerViewController(documentTypes: makeDocumentTypesList(),in: .import)
- documentsController.delegate = self
- viewControllerProvider.getViewController().present(documentsController,animated: true,completion: nil)
- }
解决方法
您只需将此代码放在应用程序中的某个位置即可重置UIDocumentPickerViewController的外观:didFinishLaunchingWithOptions:function并且条形按钮将返回其原始蓝色,或者您可以设置您选择的任何其他颜色.另一方面,条形颜色不可定制.
- if #available(iOS 11.0,*) {
- UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
- }