简体   繁体   English

如何更改UIDocumentInteractionController完成按钮文本和背景颜色

[英]How to change UIDocumentInteractionController Done button text and background color

How to change the background color and text color of done button? 如何更改完成按钮的背景颜色和文字颜色? Is there a way that I can change the navigationbar color and navigation bar title color and bottom bar color also? 有没有办法可以更改导航栏颜色和导航栏标题颜色和底栏颜色? Attached screenshot for reference: 附件截图供参考: 在此输入图像描述

I solved it. 我解决了 Here is the code working for me perfectly: 这是完美地为我工作的代码:

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
}

It's a little hacky as its relying on the fact that QLPreviewController is the class implementing the UIDocumentInteractionController but something like this is the least intrusive solution. 它有点hacky,因为它依赖于QLPreviewController是实现UIDocumentInteractionController的类,但这样的东西是最不具侵入性的解决方案。 Do it before you display the UIDocumentInteractionController 在显示UIDocumentInteractionController之前执行此操作

import QuickLook

UIBarButtonItem.appearance(whenContainedInInstancesOf [QLPreviewController.self]).tintColor = UIColor.black

I have a idear to change the bar color: 我有改变条形颜色的想法:

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

but this method has a great effect,all your UINavigationBar and UIToolBar will make that change. 但是这个方法效果很好,你的所有UINavigationBarUIToolBar都会做出改变。

Hope anyone else can give a better solusion. 希望其他人能给出更好的解决方案。

You can change the tint color of the window temporally. 您可以暂时更改窗口的色调颜色。

func presentDocument() {
    //present the controller here
    self.appDelegate.window.tintColor = UIColor.red
}

Then change it back later: 然后再改回来:

func documentInteractionControllerDidEndPreview(documentInteractionController) { //replace parameter with your uidocumentviewinteractioncontroller
    self.appDelegate.window.tintColor = UIColor.white
}

@Dee. @Dee。 I guess you have asked this part in one of your other question. 我想你已经在另一个问题中提出了这个问题。 In that case you were not able to show that preview controller. 在这种情况下,您无法显示预览控制器。 In that question suggested answer is to return "self" from that delegate method. 在那个问题中,建议的答案是从该委托方法返回“self”。 If you implement that correctly then your preview will use same navigation bar colour as its parent controller is using. 如果您正确实现,那么您的预览将使用与其父控制器使用相同的导航栏颜色。 I mean if you have opened UIDocumentInteractionController directly from some ViewController then UIDocumentInteractionController will use its parent viewController's navigation bar colour. 我的意思是如果您直接从某些ViewController打开了UIDocumentInteractionController,那么UIDocumentInteractionController将使用其父viewController的导航栏颜色。 This may help you to change Done button colour 这可以帮助您更改完成按钮颜色

Try this : (You need to implement UIDocumentInteractionControllerDelegate) 试试这个:(你需要实现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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM