5

I'm attempting to view a PDF using QLPreviewController and I'm struggling to change some of the view attributes such as Navigation Bar header and the background of the view.

I was able to change the translucency of the Navigation Bar after subclassing QLPreviewController and changing the self.navigationController.navigationBar.translucency = NO; in the didViewAppear method, however I am unable to make changes to the navigationBar.title or the backgroundColor attributes of the self.view.backgroundColor.

Both the title and the background color will flicker when the view first loads but are immediately superseded by the PDF title string and the PDF itself which overlays the background color of the view. The PDF pages appear over a black background.

I want to first know IF it's possible to subclass or otherwise change that background color to my own custom color, then I would love to know if anyone has any suggestions or know a decent solution to changing that background color.

The same goes for the title value to a lesser extent.

Kman77
  • 59
  • 4
  • did you ever get this working? I have the same issue, it flickers black... – xaphod Oct 30 '15 at 01:23
  • FYI by subclassing I got rid of the flickering issues, and an issue where the navbar just went all black sometimes when opening an item ... in my subclass viewWillAppear I have this: – xaphod Oct 30 '15 at 01:38

1 Answers1

5

In Swift 4 subclass UINavigationController and put in it:

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).isTranslucent = false
    UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).tintColor = #colorLiteral(red: 0.1889409125, green: 0.6918108463, blue: 0.9730117917, alpha: 1)
    UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
  }
Deniss Fedotovs
  • 1,384
  • 12
  • 22