UIDocumentPickerViewController - 如何设置导航栏颜色

12

我希望将我的DocumentPicker的导航栏背景颜色设置成与我的应用程序中其余部分相同的颜色。

    let filePicker = UIDocumentPickerViewController(documentTypes: ["public.content"], in: .import)
    filePicker.delegate = self
    filePicker.navigationController?.navigationBar.barTintColor = self.theme.navigationBarColor

    self.present(filePicker, animated: true, completion: nil)

无效。

我尝试过的其他方法:

使用UINavigationBar.appearance().backgroundColor = self.theme.navigationBarColor - 无效,而且看起来太像一种变通办法而不是正常工作的方法。

编辑: 现在我们的应用程序重新设计,使用主要颜色作为导航栏文本颜色,并具有与DocumentPicker相同的背景颜色。仍然欢迎回答。


3
在 iOS 11 之前,你可以使用 UINavigationBar.appearance().backgroundColor = UIColor.black 来设置导航栏背景颜色为黑色,并且它能正常工作。但是在 iOS 11 中似乎存在一个 bug。我现在遇到了一个尴尬的情况,导航栏是白色的,而导航栏按钮(比如“取消”)也是白色的,所以它们无法显示。 - JohnnyC
1
@JohnnyC 我也遇到了这个问题。 - Isuru
[UINavigationBar appearance].tintColor = [UIColor yourColor]; // 用于按钮标题颜色[UINavigationBar appearance].backgroundColor = [UIColor yourColor]; // 用于背景颜色。对我来说非常有效。我只在iOS 14版本中遇到了这个问题。 - Ravi
1个回答

3
这将改变像“取消”这样的文本的颜色。
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blue], for: .normal)

这将改变箭头的背景颜色。

UIButton.appearance().tintColor = UIColor.blue

在使用选取器后,不要忘记将其设置回原来的颜色(如果需要的话)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接