DocumentInteractionController Navigation Bar Color

2019-07-22 04:01发布

In my iOS application, I am using the DocumentInteractionController to preview the .csv document.

    self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
    [self.documentController setDelegate:self];
    [self.documentController presentPreviewAnimated:YES];

However, I am finding that the navigation bar is completely transparent. The back button is white, so it is not visible due to the white background.

Note that I have styled the navigation bar in the AppDelegate:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255.0f green:138/255.0f blue:188/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"DINPro-Bold" size:17]}];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];

Essentially, my question is how can I make the appearance of the navigation bar in the DocumentInteractionController View Controller consistent with the appearance of the navigation bar throughout the entire app (or at least visible!).

1条回答
女痞
2楼-- · 2019-07-22 04:53

This line puts a transparent (or rather void) background image to your UINavigationBar. Why is that?

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

Just remove the line and everything works well.

If you want to set a shadow image, then you should think about using appearanceWhenContainedIn: instead of appearance so it won't spread to unhandled controllers.

As for the Status Bar Style, the simplest way would be to pass self.navigationController as the presenter, instead of self:

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

Hope this will help,

查看更多
登录 后发表回答