xcode 更改 UIDocumentInteractionController 导航栏的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6855008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change color of UIDocumentInteractionController nav bar
提问by Yogesh Agarwal
Is there a way to change the tint/background color of UIDocumentInteractionController
navigationbar
?
有没有办法改变 的色调/背景颜色UIDocumentInteractionController
navigationbar
?
回答by frddsgn
A cleaner version of @DOOManics implementation:
@DOOManics 实现的更简洁版本:
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return [self navigationController];
}
回答by DOOManiac
If you put the UIDocumentInteractionController onto a UINavigationController it will automatically take the color its navbar. This is probably your root view navcontroller.
如果您将 UIDocumentInteractionController 放在 UINavigationController 上,它将自动采用其导航栏的颜色。这可能是您的根视图导航控制器。
You do this with the documentInteractionControllerViewControllerForPreview
method:
您可以使用以下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;
}
回答by Mahendra Liya
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/256.0 green:145.0/256.0 blue:35.0/256.0 alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/256.0 green:145.0/256.0 blue:35.0/256.0 alpha:1.0]];
Place this code in Appdelegate's didFinisLaunching
method. It will change the color of the navigation bar for the whole app.
将此代码放在 Appdelegate 的didFinisLaunching
方法中。它将更改整个应用程序导航栏的颜色。
回答by neha
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];
}
回答by Ankit Kumar Gupta
Swift version to @dvdfrddsgn implementation
Swift 版本到@dvdfrddsgn 实现
Try this : (You need to implement UIDocumentInteractionControllerDelegate)
试试这个:(你需要实现 UIDocumentInteractionControllerDelegate)
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self.navigationController ?? self
}
回答by Ru Cindrea
If you're not using a navigationController, you can set the navigation bar color in the UIDocumentInteractionController by setting the correct settings on the View of the UIViewController where you launch the UIDocumentInteractionController from.
如果您没有使用导航控制器,则可以通过在启动 UIDocumentInteractionController 的 UIViewController 的视图上设置正确的设置,在 UIDocumentInteractionController 中设置导航栏颜色。
Let's say you have UIViewController viewController1 (from somewhere here you launch the UIDocumentInteractionController), with a View1 in the storyboard.
假设您有 UIViewController viewController1(从这里的某个地方启动 UIDocumentInteractionController),故事板中有一个 View1。
With the Storyboard open, click on the View1 from the list of elements on the viewController1 and go to "Attributes inspectors" on the right side. The Background and the Tint set there will be used in your UIDocumentInteractionController as well afterwards.
打开 Storyboard,从 viewController1 上的元素列表中单击 View1,然后转到右侧的“属性检查器”。那里的 Background 和 Tint 设置也将在您的 UIDocumentInteractionController 之后使用。
Then you can just use:
然后你可以使用:
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
Note that inside the viewController1, you might have a Navigation Bar with different properties, and these will not be used in the UIDocumentInteractionController.
请注意,在 viewController1 中,您可能有一个具有不同属性的导航栏,而这些将不会在 UIDocumentInteractionController 中使用。