Search code examples
ios11uipageviewcontrollerpdfkitpdfview

PDFView backgroundColor when using usePageViewController


when I set the usePageViewController on my PDFView instance

pdfView?.usePageViewController(true, withViewOptions: nil)

I can no longer set the backgroundColor with

pdfView?.backgroundColor =.red

I have to(I assume) set it at the pageViewController level.

Question is how to access the pageViewController as it is not a property on the pdfView?

Also what options can be set in the usePageViewController(true, withViewOptions: ???). Be super handy of can set backgroundColor there.


Solution

  • Immediately after you call usePageViewController, the subviews of the PDF View will still be a UIScrollView. However if you wait for it to switch to the page view controller, then you can set the background color of that view.

    In my case, I was loading the document I am displaying in viewDidLoad, and I set the background color in viewDidAppear by accessing the subview of the pdf View, for example:

    self.pdfView?.subviews[0].backgroundColor = UIColor.red
    

    I would add appropriate checks to make sure that the view is there and that it is actually a page view controller view, just in case Apple's implementation changes in the future.

    Regarding your other question about the options passed to usePageViewController - those don't appear to be documented yet.