【问题标题】:UIDocumentInteractionController doesn't respect UINavigationBar's barTintColor appearance in iOS 11UIDocumentInteractionController 在 iOS 11 中不尊重 UINavigationBar 的 barTintColor 外观
【发布时间】:2017-09-14 20:37:26
【问题描述】:

我有一个示例项目,可以在应用启动时设置条形颜色:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UINavigationBar.appearance().barTintColor = UIColor.red
    return true
}

它有 1 个视图控制器(在 UINavigationController 内部),其中包含以下代码:

@IBAction func launchDocument(_ sender: Any) {
    if let url = Bundle.main.url(forResource: "example", withExtension: "pdf") {            
        let controller = UIDocumentInteractionController(url: url)
        controller.delegate = self
        controller.presentPreview(animated: false)
    }
}

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self
}

在 iOS 10 中,主视图控制器和 UIDocumentInteractionController 都有红色导航栏。在 iOS 11 中,UIDocumentInteractionController 不是红色的。这是 iOS 11 的错误吗?还是有其他方法可以做到这一点?

附: - 我知道我可以在委托中返回 self.navigationController,但我需要 UIDocumentInteractionController 有一个“完成”按钮,而不是一个“返回”按钮

【问题讨论】:

  • 有什么解决办法吗?

标签: ios swift ios11


【解决方案1】:

根据我的测试,iOS 11 公开版本中的相同问题,目前看来仅遵循 [setBarStyle]

 [[UINavigationBar appearance] setBarStyle: UIBarStyleBlack];

【讨论】:

    【解决方案2】:

    对我有用

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

    更多细节..我得到了它...... DocumentInteractionController Navigation Bar Color

    【讨论】:

      【解决方案3】:

      同样的问题。但我意识到这是关于barTintColorsetBackgroundImage 为我工作。

      • 使用您的背景颜色创建一个小图像并添加以下行:

         UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "nav_bg")?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 15, 0, 15), resizingMode: .stretch), for: .default)
        

      【讨论】:

        猜你喜欢
        • 2018-08-06
        • 2020-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-10
        • 1970-01-01
        相关资源
        最近更新 更多