iOS 修改UIDocumentPickerViewController navigation bar buttons color

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

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

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

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

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,系统的默认值)

猜你喜欢

转载自blog.csdn.net/youshaoduo/article/details/79402856