PDFSelection
bounds(forPage:)方法返回一个矩形以满足整个选择区域。不是您情况下的最佳解决方案。
尝试使用
selectionsByLine(),并为每个矩形添加单独的注释,以表示PDF中的每个选定行。例:
let selections = pdfView.currentSelection?.selectionsByLine() // Simple scenario, assuming your pdf is single-page. guard let page = selections?.first?.pages.first else { return } selections?.forEach({ selection in let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil) highlight.endLineStyle = .square highlight.color = UIColor.orange.withAlphaComponent(0.5) page.addAnnotation(highlight) })


