Dee
Dee

Reputation: 1897

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: enter image description here

Upvotes: 7

Views: 6233

Answers (7)

Ankit Kumar Gupta
Ankit Kumar Gupta

Reputation: 4042

Try this : (You need to implement UIDocumentInteractionControllerDelegate)

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
}

Upvotes: 0

user3065306
user3065306

Reputation: 21

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. Do it before you display the UIDocumentInteractionController

import QuickLook

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

Upvotes: 2

Carlos Chaguendo
Carlos Chaguendo

Reputation: 3085

     let QLNavAppearance = UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self])
    QLNavAppearance.tintColor = UIColor.red // some
    QLNavAppearance.barTintColor =  UIColor.red // some
    QLNavAppearance.backgroundColor =  UIColor.red // some

Upvotes: -1

Saurabh Shukla
Saurabh Shukla

Reputation: 1398

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
}

Upvotes: 2

Premal
Premal

Reputation: 531

@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. 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. This may help you to change Done button colour

Upvotes: 0

Papershine
Papershine

Reputation: 5223

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
}

Upvotes: 0

Guan
Guan

Reputation: 148

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 UINavigationBarand UIToolBar will make that change.

Hope anyone else can give a better solusion.

Upvotes: 1

Related Questions