首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QLPreviewController NavigationBar barTintColor

QLPreviewController NavigationBar barTintColor
EN

Stack Overflow用户
提问于 2017-12-06 11:49:13
回答 1查看 815关注 0票数 2

当我self.present() QLPreviewController时,它的NavigationBar失去了颜色,这是用AppDelegate实现的。

代码语言:javascript
复制
    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().barTintColor = Colors.fifth   // Blue color
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    UINavigationBar.appearance().shadowImage = UIImage()

QLPreviewController实现:

代码语言:javascript
复制
let preview = QLPreviewController()
preview.dataSource = self

func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
    return 1
}

func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> 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: "Произошла ошибка во время чтения файла \(url!.lastPathComponent)")
            }
        } else {
            SVProgressHUD.showDismissableError(with: error?.localizedDescription)
        }
    }
}

我尝试过self.show(),它的NavigationBarOK!我希望将QLPreviewController's NavigationBar颜色设置为与AppDelegate's UINavigationBar相同的设置。如何以编程方式更改此操作?提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2018-02-12 12:11:58

首先实例化一个UINavigationControllerQLPreviewController作为它的根视图控制器。然后,您可以显示导航栏,它将具有在app委托类中设置的属性。

代码语言:javascript
复制
    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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47673587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档