[英]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.