4

I found a PDFView and PDFThumbnailView in Object Library like this pic:

enter image description here

But my question is how to use it ??? I can't drag it in xib , and no idea to create a PDFView by code .

Any answer or tutorial will be help.

jww
  • 90,984
  • 81
  • 374
  • 818
Webber Lai
  • 2,004
  • 5
  • 35
  • 65

1 Answers1

3

Both PDFView and PDFThumbnailView are now available on iOS, as of iOS 11. Code like this should get you going:

let pdfView = PDFView()
pdfView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(pdfView)

pdfView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
pdfView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
pdfView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
pdfView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

if let document = PDFDocument(url: pathToYourPDFDocument) {
    pdfView.document = document
}
TwoStraws
  • 12,462
  • 3
  • 54
  • 70