objective c - highlight and make note in UIwebview -


i deveoping ebook app ipad/iphone loads epub file. know how highlight text background color , make notes similar ibook or kindle in uiwebview , not uiview. able drag select text long tapping. can see "copy" option. add highlight , add note menu. how hightlight text background color?... document loaded in uiwebview.

thank you.

what need add note , highlight options shared menu. in viewcontroller viewdidload (or anytime after view has been added). following adds 2 menu items 2 selector methods menu.

uimenuitem *custommenuitem1 = [[uimenuitem alloc] initwithtitle:@"highlight" action:@selector(dohighlight:)]; uimenuitem *custommenuitem2 = [[uimenuitem alloc] initwithtitle:@"note" action:@selector(donote:)]; //[myarray addobject:custommenuitem2]; nsmutablearray *myarray = [[nsmutablearray alloc]initwithobjects:custommenuitem1,custommenuitem2, nil ] ;    [uimenucontroller sharedmenucontroller].menuitems = myarray; 

you may want use bit of javascript determine rect holds selection, overlay translucent uiview on text.

so, within donote method, load javascript , run it, see below javascript example of may want do.

nsstring *rectstring = [webview stringbyevaluatingjavascriptfromstring:rectstringtext]; 

the following rect around text, though inherently larger text: if you've highlighted @ char 10 on line 2 through char 50 on line 5, return rect highlights char 0 line 2 through endline line 5.

function selectel(x,y){ document.designmode = "on"; var el = document.elementfrompoint(x, y); var rect = el.getboundingclientrect(); var vx = rect.left; var width = rect.right - vx;  var height = rect.bottom - rect.top; var vy = rect.top;  var range = document.createrange(); range.selectnodecontents(el); var sel = document.getselection(); sel.removeallranges(); sel.addrange(range); document.designmode = "off";   rectstring = '{{'+vx+','+vy+'},{'+width+','+height+'}}'; } 

so, have rectangle string, can create crect string returned , uiview overlay within webview. [note, have figure out how deal zooming , saving data next load]


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -