Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the background color of QLPreviewController?

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.

like image 655
Kman77 Avatar asked Jan 28 '15 19:01

Kman77


1 Answers

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]
  }
like image 151
Deniss Fedotovs Avatar answered Oct 29 '22 15:10

Deniss Fedotovs