1

Wenn ich self.present()QLPreviewController, verliert NavigationBar die Farbe, die in AppDelegate implementiert wurde.QLPreviewController NavigationBar BalkenTintColor

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 Umsetzung:

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) 
     } 
    } 
} 

Ich versuchte self.show() und seine NavigationBar ist OK! Ich möchte QLPreviewController's NavigationBar Farbe auf die gleichen Einstellungen wie AppDelegate's UINavigationBar setzen. Wie kann ich das programmatisch ändern? Danke im Voraus!

Antwort

0

Erste instanziiert eine UINavigationController und Ihre QLPreviewController als root-View-Controller. Dann können Sie diese Navigationsleiste darstellen und Eigenschaften haben, die Sie in der App-Delegate-Klasse festgelegt haben.

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) 
Verwandte Themen