1

I use pdfkit and I want to customize the menu contents of the selected text that appears. When I long-press and select the text, the system menu pops up with the highlight option, and nothing happens when I click on highlight. I want to customize the menu and replace the highlight copy and other options on the current system.

My code implementation:

class MyPDFVC: UIViewController, PDFViewDelegate {

let pdfView = PDFView()

override func viewDidLoad() {
    super.viewDidLoad()
    
    pdfView.frame = CGRect(x: 0, y: 0, width: 
    self.view.frame.width, height: self.view.frame.height)
    pdfView.isUserInteractionEnabled = true
    pdfView.delegate = self
    self.view.addSubview(pdfView)
    
    //加载的 PDF 文件
    if let pdfURL = Bundle.main.url(forResource: "SPR-pdf", withExtension: "pdf"), let pdfDocument = PDFDocument(url: pdfURL) {

        pdfView.document = pdfDocument
        pdfView.goToFirstPage(nil)
    }
}

}

The imageShot is: https://i.sstatic.net/FaMTn.png

5
  • Possible duplicate of How to highlight selected text in pdf using PDFKit? Commented Sep 19, 2023 at 2:38
  • thanks. I do not want to highlight the text, is it the previous step operation, because I have not yet got the selected text. I want to long-press the selected text and bring up the highlight menu for this part of the ui. For example, in the screenshot uploaded in the question, after I long press, the system will select the text and display the highlight menu, but I did not have any effect when I clicked, and I could not capture the click event to add the highlighted code you sent. I want to capture the click event or delete the highlight menu, or disable the system longpress selected text Commented Sep 19, 2023 at 2:48
  • Try changing the highlight background colour of the text selection. Also, would be easier if you could share a minimal reproducible sample of your code. Commented Sep 19, 2023 at 6:02
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 19, 2023 at 12:39
  • than you. I have edit my ask, and add my code, please help me check it. Simple to say. I want to customize the menu contents of the selected text that appears. My phone is IOS 16.0. Commented Sep 19, 2023 at 14:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.