PDFKit iOS 11中的突出显示和墨迹注释

问题描述 投票:0回答:2

我正在使用iOS 11 swift中的PDF阅读器应用程序。我需要使用墨迹注释突出显示文本和涂鸦。我一直在使用iOS PDFKit框架,但我找不到这些的示例实现。

ios swift pdf annotations ios11
2个回答
3
投票

您可以使用PdfKit Annotation :(您在执行此方法之前选择了一些文本)

PDFSelection *select = [[PDFSelection alloc] initWithDocument:_pdfView.document];
[select addSelection:_pdfView.currentSelection];
NSArray *arrayByLine = _pdfView.currentSelection.selectionsByLine;
for (PDFSelection *select in arrayByLine) {
    PDFAnnotation *annotation = [[PDFAnnotation alloc] initWithBounds:[select boundsForPage:_pdfView.currentPage] forType:PDFAnnotationSubtypeHighlight withProperties:nil];
    annotation.color =[UIColor yellowColor];
    [_pdfView.currentPage addAnnotation:annotation];
}

你可以使用很多注释:

PDFAnnotationSubtypeUnderline
PDFAnnotationSubtypeStrikeOut
PDFAnnotationSubtypeSquare
PDFAnnotationSubtypeCircle
PDFAnnotationSubtypeHighlight
.......

0
投票

基本上你需要检查PDFKit框架!

在PDFDocument类中,您将找到以下方法

open func findString(_ string: String, withOptions options: NSString.CompareOptions = []) -> [PDFSelection]

此方法将返回PDFSelection数组,您可以使用以下PDFView类方法直接将其分配给PDFView

@available(iOS 11.0, *)
open var highlightedSelections: [PDFSelection]?
© www.soinside.com 2019 - 2024. All rights reserved.