菜鸟教程小白 发表于 2022-12-11 19:24:21

ios - QLPreviewController NavigationBar barTintColor


                                            <p><p>当我<code>self.present()</code> <code>QLPreviewController</code>时,它的<code>NavigationBar</code>失去颜色,这是在<code>AppDelegate</code>中实现的>.</p>

<pre><code>    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().barTintColor = Colors.fifth   // Blue color
    UINavigationBar.appearance().titleTextAttributes =
    UINavigationBar.appearance().shadowImage = UIImage()
</code></pre>

<p><code>QLPreviewController</code> 实现:</p>

<pre><code>let preview = QLPreviewController()
preview.dataSource = self

func numberOfPreviewItems(in controller: QLPreviewController) -&gt; Int {
    return 1
}

func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -&gt; QLPreviewItem {
    return fileURL! as QLPreviewItem
}

fileprivate func showDocument(fileId: Int) {
    SVProgressHUD.show()
    self.fileService.download(id: fileId) {
      url, error in

      if error == nil {
            self.fileURL = url
            if QLPreviewController.canPreview(self.fileURL! as QLPreviewItem) {
                self.present(self.preview, animated: true, completion: nil)
                SVProgressHUD.dismiss()
            } else {
                SVProgressHUD.showDismissableError(with: &#34;Произошла ошибка во время чтения файла \(url!.lastPathComponent)&#34;)
            }
      } else {
            SVProgressHUD.showDismissableError(with: error?.localizedDescription)
      }
    }
}
</code></pre>

<p>我尝试 <code>self.show()</code> 并且它的 <code>NavigationBar</code> 是 <strong>OK</strong>!
我想将 <code>QLPreviewController 的 NavigationBar</code> 颜色设置为与 <code>AppDelegate 的 UINavigationBar</code> 具有相同的设置。如何以编程方式更改它?提前致谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>首先将 <strong>UINavigationController</strong> 和您的 <strong>QLPreviewController</strong> 实例化为它的 <strong> Root ViewController </strong>。然后,您可以显示该导航栏,该导航栏将具有您在应用委托(delegate)类中设置的属性。</p>

<pre><code>    let preview = QLPreviewController()
    preview.dataSource = self
    preview.currentPreviewItemIndex = 0
    let navBar = UINavigationController(rootViewController: preview)
    let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(self.dismissQLPreviewController))
    preview.navigationItem.leftBarButtonItem = doneButton
    self.present(navBar, animated: true)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - QLPreviewController NavigationBar barTintColor,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47673587/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47673587/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - QLPreviewController NavigationBar barTintColor