Search code examples
iphoneiosepub

How to highlight text in epub like ibooks app


I need to highlight text in epub book,when user selects the text,i can get the text,what the user has selected,but i need to highlight,the text permanently what user selected,thanks,any help will ne appreciated.enter image description here


Solution

  • There's nothing built in to iOS that will do this. Some broad techniques that might work:

    • If you're showing the book in a web view, you might be able to wrap that area in a span and style it to create a highlight.
    • If you're using Core Text, you could draw the highlight in directly, either before or after drawing the text. (Your choice will decide how the highlight affects non-black text.)
    • You could add a transparent view over the text that draws in the highlight.

    As for adding highlight-related items to the selection menu, see this Stack Overflow post. You probably won't be able to get icons in the menu like Apple does, though; that seems to be a private API. You could probably override the whole menu system if you want something closer to Apple's look, but that'll be quite a bit of work.