如何获取所选文本的边界作为 CGRect?

斐济怪兽

我正在尝试在 pdfViewer 中包含突出显示功能。但是,为了添加高亮注释,我需要将所选文本的边界作为 CGRect。有什么办法可以得到这个吗?

let annotation = PDFAnnotation(bounds: bounds, forType: .highlight, withProperties: nil)
用户11701404

获取一组选择,其中每个选择对应于所选文本的一行:

guard let selections = pdfView.currentSelection?.selectionsByLine()
     else { return }

逐行循环选择,然后循环每个选择包含的页面,然后使用选择的边界创建新的高亮注释并将其添加到页面

selections.forEach({ selection in
     selection.pages.forEach({ page in
         let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
         highlight.color = .yellow
         page.addAnnotation(highlight)
     })
 })

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章