Change color of UIDocumentInteractionController nav bar
Asked Answered
S

6

11

Is there a way to change the tint/background color of UIDocumentInteractionController navigationbar?

Sheugh answered 28/7, 2011 at 6:45 Comment(0)
A
15

A cleaner version of @DOOManics implementation:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return [self navigationController];
}
Assimilate answered 24/10, 2013 at 13:55 Comment(0)
M
4

If you put the UIDocumentInteractionController onto a UINavigationController it will automatically take the color its navbar. This is probably your root view navcontroller.

You do this with the documentInteractionControllerViewControllerForPreview method:

- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
    // Use the rootViewController here so that the preview is pushed onto the navbar stack
    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    return appDelegate.window.rootViewController;
}
Mudfish answered 10/9, 2011 at 18:16 Comment(0)
B
2

[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/256.0 green:145.0/256.0 blue:35.0/256.0 alpha:1.0]];

Place this code in Appdelegate's didFinisLaunching method. It will change the color of the navigation bar for the whole app.

Brittney answered 13/9, 2013 at 8:0 Comment(1)
this will change the color of the whole appPrescience
S
1

Try this code:

- (void)openEC:(NSURL*)url {  
     [UINavigationBar appearance].tintColor = [UIColor blueColor];  
     docController = [UIDocumentInteractionController interactionControllerWithURL:url];  
    [docController setDelegate:self];  
    [docController  presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];  
}

- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller {  
    [UINavigationBar appearance].tintColor = [UIColor whiteColor];  
}
Saponin answered 9/6, 2016 at 12:19 Comment(0)
M
1

Swift version to @dvdfrddsgn implementation

Try this : (You need to implement UIDocumentInteractionControllerDelegate)

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
} 
Montage answered 4/2, 2019 at 7:44 Comment(0)
B
0

If you're not using a navigationController, you can set the navigation bar color in the UIDocumentInteractionController by setting the correct settings on the View of the UIViewController where you launch the UIDocumentInteractionController from.

Let's say you have UIViewController viewController1 (from somewhere here you launch the UIDocumentInteractionController), with a View1 in the storyboard.

With the Storyboard open, click on the View1 from the list of elements on the viewController1 and go to "Attributes inspectors" on the right side. The Background and the Tint set there will be used in your UIDocumentInteractionController as well afterwards.

Then you can just use:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}

Note that inside the viewController1, you might have a Navigation Bar with different properties, and these will not be used in the UIDocumentInteractionController.

Benzene answered 9/3, 2014 at 13:21 Comment(1)
doesn't seem to work for me on ios7. i changed the tint and background color as you described, but the buttons of the preview view controller stay blue.Caspian

© 2022 - 2024 — McMap. All rights reserved.