更改 UIDocumentInteractionController 上的 NavigationBar 背景

Change NavigationBar background on UIDocumentInteractionController

我必须将本地 PDF 文件(文档目录)从 UIWebView 传递到其他应用程序(iBooks、Facebook Messenger、WhatsApp 等)。

所以我使用 UIDocumentInteractionController:

- (IBAction)shareButton:(id)sender
{
    NSURL *url = [NSURL URLWithString:self.webView.request.URL.absoluteString];

    self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
    self.docController.delegate = self;
    [self.docController presentOpenInMenuFromBarButtonItem:sender animated:YES];
}

如果我 select FB Messenger 或 WhatsApp 它显示 ViewController。

如何更改此 VC(背景 image/color、按钮色调)的 NavigationBar 外观?默认白色半透明就好了

我在 AppDelegate 中设置了 NavigationBar 背景图片。

如果你使用这一行,那么只需删除这一行,一切正常。

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

至于状态栏样式,最简单的方法是将 self.navigationController 作为演示者传递,而不是 self:

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

可能对您有所帮助

试试这个代码:

- (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];  

}