How to change UIDocumentInteractionController Done button text and background color
Asked Answered
L

7

7

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

Lankford answered 2/3, 2017 at 7:15 Comment(4)
Where is the screenshotStarshaped
I am able to see the attached screenshot. Is it not visible to you? Do I need to upload it again?Lankford
I can see it now, just now it said 'imgur is over capacity'Starshaped
@Dee: Have you solved it yet? I have the same problem. I set BarTintColor, but it seem not effect.Copulate
K
2

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
}
Kennedy answered 7/7, 2017 at 13:34 Comment(2)
Works fine but don't forget to set back to whatever you had before! I do this in the "viewWillAppear" in the view that presented the preview.Preestablish
I have a lot of customization in AppDelegate.swift. To get correct colors in the preview window (and all subviews) I had to remove this in AppDelegate: window?.tintColor = x And add this to the above list: UILabel.appearance().textColor = CommonColors.appleTint UIButton.appearance().tintColor = CommonColors.appleTintPreestablish
G
2

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
Golter answered 31/1, 2018 at 11:5 Comment(1)
For Swift 4: UIBarButtonItem.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).tintColor = UIColor.black It works for the preview but how to change the tint color of "OpenInMenu" footer when sharing the file (pressing sharing button in the preview view)? Same as docController.presentOpenInMenu.Preestablish
R
1

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.

Randall answered 2/3, 2017 at 8:50 Comment(0)
S
0

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
}
Starshaped answered 2/3, 2017 at 9:46 Comment(0)
S
0

@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

Selassie answered 2/3, 2017 at 12:54 Comment(2)
I am able to modify the navigationbar button title and text and background color now. but the bottom toolbar color is not working. Could you please help me with thatLankford
@Lankford I am unable to modify the navigationbar button title and text and background color. How you did it?Kennedy
F
0

Try this : (You need to implement UIDocumentInteractionControllerDelegate)

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
}
Fant answered 4/2, 2019 at 7:42 Comment(0)
C
-1
     let QLNavAppearance = UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self])
    QLNavAppearance.tintColor = UIColor.red // some
    QLNavAppearance.barTintColor =  UIColor.red // some
    QLNavAppearance.backgroundColor =  UIColor.red // some
Curzon answered 11/12, 2017 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.