Sebastien
Sebastien

Reputation: 4295

UIDocumentInteractionController doesn't take into account navigation bar tint color

One of the screens in my app shows a preview of a local image and I have an action button in the top left corner that I'm using to present document interaction options:

- (IBAction)actionButtonTapped:(id)sender {
    self.interactionController = [UIDocumentInteractionController interactionControllerWithURL:self.attachmentLocalUrl];
    self.interactionController.delegate = self;
    [self.interactionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
}

This works well as it shows an action sheet with a list of options, including email to send the attachment by email. When I click the email button, it displays a preview of the email message with my image in it. But there is one thing that doesn't work. I have customized the appearance of my app so that the navigation bar has the same colors throughout the app. Here is the code I run first in my app delegate's didFinishLaunchingWithOptions:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[UINavigationBar appearance].barTintColor = [UIColor blueColor];
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
[UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

This works well for my own view controllers, but the email preview view controller displayed by UIDocumentInteractionController has its bar button items in blue instead of white. And since the other parameters are correctly applied, especially the blue background for the navigation bar, the Cancel and Send action buttons are almost invisible.

I have tried reproducing this in a simple project but I couldn't. So obviously I'm doing something in my app to interfere with the normal customization. But I can't figure out what. Any idea how I might debug that?

Upvotes: 2

Views: 2779

Answers (3)

Saurabh Shukla
Saurabh Shukla

Reputation: 1398

Here is what perfectly worked for me:

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: 1

Ray Fix
Ray Fix

Reputation: 5645

I settled on the workaround to clear the customization before presenting the UIDocumentController and then restore my custom theme in viewWillAppear() of the view controller presenting the UIDocumentController.

func launchDocumentController() {
   UINavigationBar.appearance().titleTextAttributes = nil
   UINavigationBar.appearance().barTintColor = nil
   UINavigationBar.appearance().tintColor = nil
   documentController.presentOptionsMenuFromRect(self.view.frame, inView: self.view, animated: true)
}

Then

public override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    // Restore the reset bar colors
    Theme.current.customizeAppearance()
}

Short of an OS update, I think this is the best 'answer' your are going to get. Sorry. (When I get a chance I will file a radar.)

In the cases where you have direct access to MFMComposeViewController setting the tint color as described above, is a good workaround.

Upvotes: 1

Jh2170
Jh2170

Reputation: 166

Can you clarify exactly what you are meaning? Is the colors on the navigation bar screwed up on the documentpicker or the mfmailcomposer? Here's some code for either though that I had to use...

If it's on the UIDocumentPicker, set this before calling present:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
    [[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
}

and then change it back to the colors you had in the didPickDocument and didCancel Delegates

if it's on the MFMailcomposer controller then use this:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
    [controller.navigationBar setTintColor:[UIColor blackColor]];
}

Hope this helps

Upvotes: 1

Related Questions