swift – iOS 16 PDFView highlight button doing nothing & can’t override


I’m trying to make a custom highlight functionality in PDFKit’s PDFView on iOS 16. I’ve tried everything recommended online, and it seems like there’s no way to fully override the menu and remove the normal “Highlight” action which actually does nothing if you tap it.

I’d be okay with being able to either remove the base Highlight action because I’m able to add my own, or figure out how to handle a tap on that button. Here’s what I’ve tried, and the result: screenshot of result

override func buildMenu(with builder: UIMenuBuilder) {
        super.buildMenu(with: builder)

        builder.remove(menu: .application)
        builder.remove(menu: .lookup)
        builder.remove(menu: .learn)
        builder.remove(menu: .find)
        builder.remove(menu: .file)
        builder.remove(menu: .edit)
        builder.remove(menu: .services)

        if #available(iOS 16.0, *) {
            builder.remove(menu: .document)
        }

        let highlightAction = UIAction(title: "Highlight 2", attributes: []) { _ in
                 print("This works")
            }
        }

        let highlightMenu = UIMenu(title: "Highlight 2", options: [.displayInline], children: [highlightAction])

        builder.remove(menu: .standardEdit)
        builder.remove(menu: .share)
        builder.remove(menu: .toolbar)
        builder.remove(menu: .text)
        builder.remove(menu: .font)
        builder.remove(menu: .format)
        builder.remove(menu: .transformations)
        builder.remove(menu: .preferences)
        builder.remove(menu: .window)
        builder.remove(menu: .view)
        
        builder.replaceChildren(ofMenu: .root, from: { _ in [highlightAction] })
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img