【问题标题】:DocumentInteractionController Navigation Bar ColorDocumentInteractionController 导航栏颜色
【发布时间】:2014-08-02 00:26:05
【问题描述】:

在我的 iOS 应用程序中,我使用 DocumentInteractionController 来预览 .csv 文档。

    self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
    [self.documentController setDelegate:self];
    [self.documentController presentPreviewAnimated:YES];

但是,我发现导航栏是完全透明的。后退按钮是白色的,因此由于白色背景,它是不可见的。

请注意,我在 AppDelegate 中设置了导航栏的样式:

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255.0f green:138/255.0f blue:188/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"DINPro-Bold" size:17]}];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];

本质上,我的问题是如何使 DocumentInteractionController View Controller 中导航栏的外观与整个应用程序中导航栏的外观保持一致(或至少可见!)。

【问题讨论】:

  • 你能发一张其他导航栏的截图吗?
  • 方法– documentInteractionControllerViewControllerForPreview:返回什么

标签: ios uinavigationbar uidocumentinteraction


【解决方案1】:

这一行将透明(或者更确切地说是空的)背景图像放置到您的 UINavigationBar。这是为什么呢?

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

只需删除该行,一切正常。

如果你想设置一个阴影图像,那么你应该考虑使用appearanceWhenContainedIn:而不是appearance,这样它就不会传播到未处理的控制器。

对于状态栏样式,最简单的方法是传递self.navigationController作为演示者,而不是self:

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

希望这会有所帮助,

【讨论】:

  • 感谢您的回复!事实证明,这条线导致了这个问题,但我这样做的原因是我可以通过设置阴影图像来创建一个白色分隔符。如果是这种情况,您是否建议使用分隔符创建新的背景图像?不幸的是,标题仍然是黑色的,即使我将状态栏样式设置为 UIStatusBarStyleLightContent。
  • 有什么办法让我在没有 [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; 的情况下显示阴影?
  • 我最终为导航栏使用了常规壁纸。谢谢!
猜你喜欢
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-06
  • 2020-08-12
  • 2017-12-07
  • 2017-09-08
相关资源
最近更新 更多