在 UIwebview 中突出显示并做笔记
我正在为 ipad/iphone 开发一个电子书应用程序,它加载 epub 文件。我想知道如何突出显示具有背景颜色的文本,并在 UIWebView 而不是 UIView 中做类似于 iBook 或 Kindle 的笔记。我可以通过长按来拖动选择文本。但我只能看到“复制”选项。我想添加突出显示并添加注释到该菜单。如何用背景颜色突出显示文本?...我的文档已加载到 UIWebView 中。
谢谢。
I am deveoping an ebook app for ipad/iphone which loads epub file. I would like to know how to highlight a text with a background color and make notes similar to iBook or Kindle in UIWebView and NOT UIView. I am able to drag select the text by long tapping. But I can only see "copy" option. I would like to add highlight and add note to that menu. How to hightlight the text with a background color?... My document is loaded in UIWebView.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是将注释和突出显示选项添加到共享菜单中。在您的视图控制器 viewdidload 中(或添加视图后的任何时间)。下面将两个具有两种选择器方法的菜单项添加到您的菜单中。
您可能还想使用一些 JavaScript 来确定保存您的选择的矩形,然后在文本上覆盖半透明的 uiview。
因此,在您的 doNote 方法中,加载 javascript 并运行它,请参阅下面的 javascript 以获取您可能想要执行的操作的示例。
下面的代码将在文本周围得到一个矩形,尽管它本身会比您的文本大:如果您突出显示了第 2 行的 char 10 到第 5 行的 char 50,它将返回一个突出显示第 2 行到 char 0 的矩形endline 第 5 行。
现在您有了一个矩形字符串,您可以从返回的字符串和 uiview 创建一个 CRect 以覆盖在您的 web 视图中。 [注意,您必须弄清楚如何处理缩放并保存此数据以供下次加载]
What you need to do is add the note and highlight options to your shared menu. In your viewcontroller viewdidload (or anytime after your view has been added). The following adds two menu items with two selector methods to your menu.
You may also want to use a bit of javascript to determine the rect that holds your selection, then overlay a translucent uiview over the text.
So, within your doNote method, load up javascript and run it, see the below javascript for an example of what you may want to do.
The following will get a rect around the text, though it will inherently be larger than your text: if you've highlighted at char 10 on line 2 through char 50 on line 5, it will return a rect that highlights char 0 line 2 through endline line 5.
So, now that you have a rectangle string, you can create a CRect from the string returned and uiview to overlay within your webview. [Note, you will have to figure out how to deal with zooming and saving this data for your next load]