2011-07-28 207 views

回答

3

如果您將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方法的代碼。它會改變整個應用程序導航欄的顏色。

+0

這將改變整個應用程序 –

10

一個清潔的版本@DOOManics實現:

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

巨大答案的顏色.. –

0

如果你不使用navigationController,你可以通過在這裏的UIViewController的視圖設置正確的設置,設置在UIDocumentInteractionController導航欄顏色你從中啓動UIDocumentInteractionController。

比方說,你有UIViewController的viewController1(從這裏你啓動UIDocumentInteractionController),與故事板中的View1。

打開Storyboard後,單擊viewController1上元素列表中的View1,然後轉到右側的「屬性檢查器」。這裏設置的Background和Tint將會在你的UIDocumentInteractionController中使用。

然後,你可以使用:

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

注意,viewController1裏面,你可能有一個導航欄具有不同的屬性,它們不會在UIDocumentInteractionController使用。

+0

似乎並沒有爲工作我在ios7上。我按照上述說明改變了色調和背景顏色,但預覽視圖控制器的按鈕保持藍色。 – kritzikratzi

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

}