更改UIDocumentInteractionController导航栏的颜色

11

有没有办法改变UIDocumentInteractionController navigationbar的色调/背景颜色?

6个回答

15

@DOOManics的实现的简洁版本:

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

4
如果将UIDocumentInteractionController放在UINavigationController上,它会自动采用其导航栏的颜色。这很可能是你的根视图navcontroller。
你可以使用documentInteractionControllerViewControllerForPreview方法实现此功能:
- (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;
}

2

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

将此代码放置在Appdelegate的didFinisLaunching方法中。它将更改整个应用程序导航栏的颜色。


这将改变整个应用程序的颜色。 - Alberto M

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

1

将Swift版本应用于@dvdfrddsgn的实现

尝试这样做:(您需要实现UIDocumentInteractionControllerDelegate)

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
} 

0

如果您没有使用navigationController,您可以在UIViewController的视图上设置正确的设置来设置UIDocumentInteractionController中的导航栏颜色。

假设您有UIViewController viewController1(从这里启动UIDocumentInteractionController),并且在故事板中有一个View1。

打开Storyboard,在viewController1的元素列表中单击View1,然后转到右侧的“属性检查器”。以后, UIDocumentInteractionController中将使用此处设置的背景和Tint。

然后您只需使用:

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

请注意,在viewController1内,您可能会有一个具有不同属性的导航栏,但这些属性将不会在UIDocumentInteractionController中使用。

在iOS7上似乎对我不起作用。我按照您描述的更改了色调和背景颜色,但预览视图控制器的按钮仍然是蓝色的。 - kritzikratzi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接