Highlite Select Text in UIWebview

谁说胖子不能爱 提交于 2020-01-16 18:35:21

问题


i want to Select text using gesture and highlite that text.i had done display html page in UIwebview but uiwebview does not fire touch begin event, So how can i do.

1) when user select text (i.e user select text "i Know uesr" that part of text color should be change.

if you have any idea below of the query,kindly suggest me..

Thank you

Milan


回答1:


If you look at the docs for a UIWebView, you know your options are limited. You're going to have do it with javascript. Your only weapon is - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script and your ability to load every page as a string (which you can manipulate) before passing it to you UIWebView as a page (using - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL).

So... good luck with that. ;)




回答2:


Brute force method

You can trap the touches as the Window level by subclassing UIWindow. Then you can manually locate the view the touch occurred in and then the location in the view.

As to actually highlighting the text with the OS, I think you might have to put a transparent overlay view on top of the webview and then draw the highlight there.

You're going to have trouble selecting in a webview because a single touch also opens links. You're going to have to create an interface that distinguishes between link touches and selection touches.



来源:https://stackoverflow.com/questions/1721064/highlite-select-text-in-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!