Objective c 更改UIDocumentInteractionController导航栏的颜色

Objective c 更改UIDocumentInteractionController导航栏的颜色,objective-c,xcode,ios4,uidocumentinteraction,Objective C,Xcode,Ios4,Uidocumentinteraction,是否有方法更改UIDocumentInteractionController导航栏的色调/背景色 如果将UIDocumentInteractionController放在UINavigationController上,它将自动将颜色带到导航栏上。这可能是您的根视图导航控制器 您可以使用DocumentInteractionControllerServiceControllerForpReview方法执行此操作: - (UIViewController *) documentInteraction

是否有方法更改
UIDocumentInteractionController
导航栏的色调/背景色

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

您可以使用
DocumentInteractionControllerServiceControllerForpReview
方法执行此操作:

- (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外观]setTintColor:[uicolorWithred:107.0/256.0绿色:145.0/256.0蓝色:35.0/256.0 alpha:1.0]


将此代码放入Appdelegate的
DidFinishLaunching
方法中。它将改变整个应用程序导航栏的颜色。

更干净的@DOOManics实现版本:

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

如果未使用navigationController,则可以通过在启动UIDocumentInteractionController的UIViewController的视图上设置正确的设置来设置UIDocumentInteractionController中的导航栏颜色

假设您有UIViewController viewController1(从这里的某个地方启动UIDocumentInteractionController),故事板中有一个View1

在情节提要打开的情况下,单击viewController1上元素列表中的View1,然后转到右侧的“属性检查器”。那里的背景和色调集也将在您的UIDocumentInteractionController中使用

然后您可以使用:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}
请注意,在viewController1中,您可能有一个具有不同属性的导航栏,这些属性不会在UIDocumentInteractionController中使用

请尝试以下代码:

- (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版本至@dvdfrdsgn实施

尝试:(您需要实现UIDocumentInteractionControllerDelegate)


在ios7上似乎对我不起作用。如您所述,我更改了色调和背景色,但预览视图控制器的按钮保持蓝色。这将更改整个应用程序的颜色
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
}