我正在使用 PDFKit 来显示简单的 PDF。当我在 UIView 内的屏幕上显示它们时,我使用了下面的代码。
目标: - 从内容开始填充视图 - 想要明智地填充整个屏幕宽度
override func viewDidLoad() {
super.viewDidLoad()
if let path = Bundle.main.path(forResource: "Disclaimer", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.document = pdfDocument
pdfView.autoScales = true
pdfView.maxScaleFactor = 4.0
pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
pdfView.displayMode = .singlePageContinuous
pdfView.displaysPageBreaks = false
}
}
self.view.backgroundColor = UIColor.black
}
在情节提要中,我为 UIview 设置了一个约束来填充屏幕的整个宽度 - 它确实如此。
使用autoscale
销售小于屏幕宽度的PDF文档,它基本上在pdf周围添加了一个边距。我可以放大并让他的 Pdf 填满整个屏幕,在它溢出和滚动条发挥作用之前。
如果我手动设置比例因子,我可以使单页 PDF 明智地填充屏幕宽度,但如果 PDF 有多个页面,则宽度会恢复为小于屏幕宽度的margin
礼物。
最终,我只想用 PDF 填充整个屏幕宽度,没有任何边距/间隙。
将不胜感激一些帮助。
更新:按照以下建议使用的代码 - 但目前不起作用:
if let path = Bundle.main.path(forResource: pdfObject, ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: pdfView.frame.width, height: pdfView.frame.height))
pdfView.document = pdfDocument
}
}
注意: pdfView 是我的 UIView 即 PDFView