修改UIDocumentPickerViewController navigation bar buttons color

最近在研究UIDocumentPickerViewController的使用,发现微信的UIDocumentPickerViewController上面Button的颜色都是微信绿,所以自己研究了一下,看看如何自定义这些Button的颜色。

新建一个ViewContorller继承于UIDocumentPickerViewController,然后再viewWillAppear的时候通过这几句代码设置

1
2
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor:self.view.tintColor], for: .normal)
UIButton.appearance().tintColor = self.view.tintColor

这里的tintColor可以设置成任意的颜色,这里是设置成系统自己的颜色。

当然要做到像微信那样全是绿色,可以把下面这几个也设置上:

1
2
3
UIImageView.appearance().tintColor = self.view.tintColor
UITabBar.appearance().tintColor = self.view.tintColor
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = self.view.tintColor

千万要记住在页面dismiss之后,将这些tintColor设置成原来的值(如果原来没设置,就设置为self.view.tintColor,系统的默认值)

文章目录
|