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
  • 97,681
  • 90
  • 411
  • 885
Webber Lai
  • 2,014
  • 5
  • 35
  • 66

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,862
  • 3
  • 57
  • 71