11

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

4

6 回答 6

15

@DOOManics 实现的更简洁版本:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return [self navigationController];
}
于 2013-10-24T13:55:22.723 回答
4

如果您将 UIDocumentInteractionController 放到 UINavigationController 上,它将自动为其导航栏设置颜色。这可能是您的根视图导航控制器。

您可以使用以下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;
}
于 2011-09-10T18:16:18.153 回答
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方法中。它将改变整个应用程序导航栏的颜色。

于 2013-09-13T08:00:17.843 回答
1

@dvdfrddsgn 实现的 Swift 版本

试试这个:(你需要实现 UIDocumentInteractionControllerDelegate)

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
} 
于 2019-02-04T07:44:46.737 回答
1

试试这个代码:

- (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];  
}
于 2016-06-09T12:19:53.683 回答
0

如果您不使用导航控制器,则可以通过在启动 UIDocumentInteractionController 的 UIViewController 的视图上设置正确的设置来设置 UIDocumentInteractionController 中的导航栏颜色。

假设您有 UIViewController viewController1(从这里启动 UIDocumentInteractionController),在情节提要中有一个 View1。

在 Storyboard 打开的情况下,从 viewController1 的元素列表中单击 View1,然后转到右侧的“属性检查器”。之后设置的背景和色调也将在您的 UIDocumentInteractionController 中使用。

然后你可以使用:

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

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

于 2014-03-09T13:21:02.530 回答