Ranveer Singh
Ranveer Singh

Reputation: 11

not getting highlight option in "menu" in pdfview in ios swift

enter image description here

I am getting only these 3 options every time while my whole code is working any help will be appreciated.

let selections = pdfView.currentSelection?.selectionsByLine()
        guard (selections?.first?.pages.first) != nil else { return }
        selections?.forEach({ selection in
            let newAnnotation = PDFAnnotation(bounds: selection.bounds(for: pdfView.currentPage!) ,forType: PDFAnnotationSubtype.highlight ,withProperties: nil)
            // Add additional properties to the annotation
            newAnnotation.color = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
            self.pdfView.currentPage?.displaysAnnotations = true

            self.pdfView.currentPage?.addAnnotation(newAnnotation)
        })

Upvotes: 1

Views: 639

Answers (1)

Philip De Vries
Philip De Vries

Reputation: 415

I'm struggling with this question as well, but cannot find any option to add it to PDFView in iOS. In the end I stumbled on a general method of adding menu-items via the shared UIMenuController class.

let menuItem    = UIMenuItem(title: "Highlight", action: #selector(HighLightHandler.highlightSelection(_:)))
UIMenuController.shared.menuItems = [menuItem]

And handle any the highlight:

@objc func highlightSelection(_ sender: UIMenuItem) {
        //put your highlighting code here
}

Upvotes: 1

Related Questions