【发布时间】:2020-02-06 22:33:09
【问题描述】:
我将 pdfdocument 添加到 PDFView 。但它正在显示边缘,也显示在慢跑中。如何删除此边距。有没有办法将 pdfdocument 设置为左上角。
【问题讨论】:
标签: swift pdfview ios-pdfkit swift5.1 apple-pdfkit
我将 pdfdocument 添加到 PDFView 。但它正在显示边缘,也显示在慢跑中。如何删除此边距。有没有办法将 pdfdocument 设置为左上角。
【问题讨论】:
标签: swift pdfview ios-pdfkit swift5.1 apple-pdfkit
我认为这将有助于解决问题。
https://developer.apple.com/documentation/pdfkit/pdfview/2881210-pagebreakmargins
只需通过传递UIEdgeInsets 值来为此变量pageBreakMargins 设置一个值。
类似的东西
self.pdfView.pageBreakMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
【讨论】:
这里是示例代码:
private func openPdf() {
let pdfView = PDFView(frame: CGRect(x: 0, y: 20, width: self.view.frame.width, height: self.view.frame.height))
view.addSubview(pdfView)
guard let path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
if let document = PDFDocument(url: path) {
pdfView.document = document
pdfView.pageShadowsEnabled = false
pdfView.displayMode = .singlePage
pdfView.autoScales = true
pdfView.frame.size.height = pdfView.documentView?.frame.height ?? self.view.frame.height
self.view.layoutIfNeeded()
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
}
}
【讨论】: