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

Ios 如何更改UIDocumentInteractionController完成按钮文本和背景色,ios,iphone,swift,uinavigationcontroller,uidocumentinteraction,Ios,Iphone,Swift,Uinavigationcontroller,Uidocumentinteraction,如何更改“完成”按钮的背景颜色和文本颜色?有没有一种方法可以同时更改导航栏颜色、导航栏标题颜色和底部栏颜色?附加的屏幕截图供参考: 我有一个更改条形图颜色的主意: let allNavigationBar = UINavigationBar.appearance() allNavigationBar.barTintColor = UIColor.red // change the bar background color allNavigationBar.tintColor = UIColor

如何更改“完成”按钮的背景颜色和文本颜色?有没有一种方法可以同时更改导航栏颜色、导航栏标题颜色和底部栏颜色?附加的屏幕截图供参考:

我有一个更改条形图颜色的主意:

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
}

@迪伊。我猜你在另一个问题中问过这部分。在这种情况下,您无法显示预览控制器。在这个问题中,建议的答案是从委托方法返回“self”。如果您正确地实现了这一点,那么预览将使用与其父控制器相同的导航栏颜色。我的意思是,如果您直接从某个ViewController打开UIDocumentInteractionController,那么UIDocumentInteractionController将使用其父ViewController的导航栏颜色。这可能会帮助您更改“完成”按钮的颜色

我解决了它。下面是对我非常有效的代码:

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
}

这有点像黑客,因为它依赖于这样一个事实:QLVeviewController是实现UIDocumentInteractionController的类,但类似的东西是入侵性最小的解决方案。在显示UIDocumentInteractionController之前执行此操作

import QuickLook

UIBarButtonItem.appearance(whenContainedInInstancesOf [QLPreviewController.self]).tintColor = UIColor.black
尝试:(您需要实现UIDocumentInteractionControllerDelegate)


截图在哪里?我可以看到附带的截图。你看不见吗?我需要再上传一次吗?我现在可以看到了,刚才上面写着“imgur超负荷了”@Dee:你解决了吗?我也有同样的问题。我设置了BarTintColor,但似乎没有效果。我现在可以修改导航栏按钮标题、文本和背景色。但是底部工具栏的颜色不起作用。你能帮我做点什么吗that@Dee我无法修改导航栏按钮标题、文本和背景色。您是如何做到的?对于Swift 4:uiBarButtonim.appearance(当包含实例时:[QLPreviewController.self])。tintColor=UIColor.black它适用于预览,但如何在共享文件时更改“OpenInMenu”页脚的色调(在预览视图中按共享按钮)?与docController.presentOpenInMenu.相同,工作正常,但不要忘记恢复到以前的状态!我在显示预览的视图中的“ViewWillExample”中执行此操作。我在AppDelegate.swift中进行了大量自定义。为了在预览窗口(和所有子视图)中获得正确的颜色,我必须在AppDelegate:window?.tintColor=x中删除它,并将其添加到上面的列表:UILabel.appearance().textColor=CommonColors.appleTint UIButton.appearance().tintColor=CommonColors.appleTint
import QuickLook

UIBarButtonItem.appearance(whenContainedInInstancesOf [QLPreviewController.self]).tintColor = UIColor.black
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
}