QLPreviewController NavigationBar barTintColor
Posted
技术标签:
【中文标题】QLPreviewController NavigationBar barTintColor【英文标题】: 【发布时间】:2017-12-06 11:49:13 【问题描述】:当我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()
并且它的NavigationBar
是好的!
我想将QLPreviewController's NavigationBar
颜色设置为与AppDelegate's UINavigationBar
相同的设置。如何以编程方式更改它?提前致谢!
【问题讨论】:
【参考方案1】:首先将 UINavigationController 和您的 QLPreviewController 实例化为它的 根视图控制器。然后您可以显示该导航栏,该导航栏将具有您在应用委托类中设置的属性。
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)
【讨论】:
以上是关于QLPreviewController NavigationBar barTintColor的主要内容,如果未能解决你的问题,请参考以下文章
iOS7 QLPreviewController 改变导航栏颜色?
SwiftUI 中的 QLPreviewController 缺少导航栏