[英]How to change UIDocumentInteractionController Done button text and background color
我解决了 这是完美地为我工作的代码:
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
UINavigationBar.appearance().barTintColor = Colors.redColor()
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)]
return self
}
它有点hacky,因为它依赖于QLPreviewController是实现UIDocumentInteractionController的类,但这样的东西是最不具侵入性的解决方案。 在显示UIDocumentInteractionController之前执行此操作
import QuickLook
UIBarButtonItem.appearance(whenContainedInInstancesOf [QLPreviewController.self]).tintColor = UIColor.black
我有改变条形颜色的想法:
let allNavigationBar = UINavigationBar.appearance()
allNavigationBar.barTintColor = UIColor.red // change the bar background color
allNavigationBar.tintColor = UIColor.black // change the Done button's tintColor
let alloolbar = UIToolbar.appearance()
allToolbar.barTintColor = UIColor.red // dones't work, try backgroundImage
allToolbar.backgroundColor = UIColor.blue // dones't work
allToolbar.tintColor = UIColor.brown // change the toolbar's item tint color
但是这个方法效果很好,你的所有UINavigationBar
和UIToolBar
都会做出改变。
希望其他人能给出更好的解决方案。
您可以暂时更改窗口的色调颜色。
func presentDocument() {
//present the controller here
self.appDelegate.window.tintColor = UIColor.red
}
然后再改回来:
func documentInteractionControllerDidEndPreview(documentInteractionController) { //replace parameter with your uidocumentviewinteractioncontroller
self.appDelegate.window.tintColor = UIColor.white
}
@Dee。 我想你已经在另一个问题中提出了这个问题。 在这种情况下,您无法显示预览控制器。 在那个问题中,建议的答案是从该委托方法返回“self”。 如果您正确实现,那么您的预览将使用与其父控制器使用相同的导航栏颜色。 我的意思是如果您直接从某些ViewController打开了UIDocumentInteractionController,那么UIDocumentInteractionController将使用其父viewController的导航栏颜色。 这可以帮助您更改完成按钮颜色
试试这个:(你需要实现UIDocumentInteractionControllerDelegate)
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self.navigationController ?? self
}
let QLNavAppearance = UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self])
QLNavAppearance.tintColor = UIColor.red // some
QLNavAppearance.barTintColor = UIColor.red // some
QLNavAppearance.backgroundColor = UIColor.red // some
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.