When we highlight a text in UIWebView usually the copy, paste, define.. etc appears. How can I intercept this so that when I choose copy I call some other method/do something else. Is this possible?
When we highlight a text in UIWebView usually the copy, paste, define.. etc appears.
Share
You can simply override -copy:
Edit to answer your comment.
Define is a bit trickier, since it’s private. However, you could implement your own method. Set up the UIMenuController with your desired items.
Then you implement those methods.
As for define, it’s way more complicated.. First, you need to check if the UIReferenceLibraryController has a definition, by overriding -canPerformAction:withSender:
-selectedText is here a category on UIWebView:
Then you need to implement myDefine:
Edit to answer you comment again
-rectForSelectedText is another custom category on UIWebView.
What it does is calling a javascript that returns a string that you can convert using CGRectFromString(), it looks something like this:
Check this page to learn how to inject javascript into UIWebView.