gpt4 book ai didi

ios - QLPreviewController NavigationBar barTintColor

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:05:52 29 4
gpt4 key购买 nike

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

    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 实现:

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 的 NavigationBar 颜色设置为与 AppDelegate 的 UINavigationBar 具有相同的设置。如何以编程方式更改此设置?提前致谢!

最佳答案

首先将 UINavigationController 和您的 QLPreviewController 实例化为它的 Root View Controller 。然后您可以显示该导航栏,它将具有您在应用程序委托(delegate)类中设置的属性。

    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)

关于ios - QLPreviewController NavigationBar barTintColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47673587/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com