使用以下代码突出显示 pdf 中的搜索文本字符串。
let selections = pdfView?.document?.findString(searchTerms!, withOptions: [.caseInsensitive])
selections?.forEach { selection in
selection.pages.forEach { page in
let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
highlight.endLineStyle = .square
highlight.color = #colorLiteral(red: 0.9843137255, green: 0.9019607843, blue: 0.5529411765, alpha: 1)
page.addAnnotation(highlight)
}
}
它非常适用于小型 pdf。但是当有大约 2000 个或更多页面时,应用程序会冻结。选择需要一些时间。有没有办法来解决这个问题。也尝试了 beginDocumentFind 的委托。结果相同