有没有办法改变UIDocumentInteractionController
navigationbar
的色调/背景颜色?
有没有办法改变UIDocumentInteractionController
navigationbar
的色调/背景颜色?
@DOOManics的实现的简洁版本:
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return [self navigationController];
}
- (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;
}
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/256.0 green:145.0/256.0 blue:35.0/256.0 alpha:1.0]];
将此代码放置在Appdelegate的didFinisLaunching
方法中。它将更改整个应用程序导航栏的颜色。
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];
}
将Swift版本应用于@dvdfrddsgn的实现
尝试这样做:(您需要实现UIDocumentInteractionControllerDelegate)
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self.navigationController ?? self
}
如果您没有使用navigationController,您可以在UIViewController的视图上设置正确的设置来设置UIDocumentInteractionController中的导航栏颜色。
假设您有UIViewController viewController1(从这里启动UIDocumentInteractionController),并且在故事板中有一个View1。
打开Storyboard,在viewController1的元素列表中单击View1,然后转到右侧的“属性检查器”。以后, UIDocumentInteractionController中将使用此处设置的背景和Tint。
然后您只需使用:
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}