iPhone 开发:在 UIWebView 上抓取选定/突出显示的文本

iPhone Development: Grabbing selected/highlighted text on UIWebView(iPhone 开发:在 UIWebView 上抓取选定/突出显示的文本)

本文介绍了iPhone 开发:在 UIWebView 上抓取选定/突出显示的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

请就我如何在 UIWebVIew 上获取所选文本提出建议.

Please kindly advice on how possibly I can get the selected text on UIWebVIew.

我继续搜索如何处理选定/突出显示的文本并发现以下内容:

I went on to search on how to deal with selected/highlighted text and found the following:

选择和菜单管理

要在视图中复制或剪切某些内容,必须选择某物".它可以是一系列文本、图像、URL、颜色或任何其他数据的表示,包括自定义对象.实施自定义中的复制和粘贴行为视图,你必须管理的选择自己在那个视图中的对象.如果用户通过以下方式选择视图中的对象做出特定的触摸手势(例如例如,双击)您必须处理该事件,在内部记录选择(并取消选择任何以前的选择),也许在视觉上指出新的选择看法.如果用户可以在视图中选择多个对象对于复制剪切粘贴操作,您必须实现多重选择行为.

To copy or cut something in a view, that "something" must be selected. It can be a range of text, an image, a URL, a color, or any other representation of data, including custom objects. To implement copy-and-paste behavior in your custom view, you must manage the selection of objects in that view yourself. If the user selects an object in the view by making a certain touch gesture (for example, a double-tap) you must handle that event, internally record the selection (and deselect any previous selection), and perhaps visually indicate the new selection in the view. If it is possible for users to select multiple objects in your view for copy-cut-paste operations, you must implement that multiple-selection behavior.

这就是我迷路的地方....记录选择" - 我什至不确定如何表示选择,更不用说记录它了.

And that's where I got lost. "...record the selection" - I'm not even sure how to represent a selection let alone recording it.

非常感谢任何帮助.^^ 干杯!

Any help is very much appreciated. ^^ Cheers!

亲切的问候,呜呜呜

推荐答案

你可以使用stringByEvaulatingJavaScriptFromString 获取 UIWebView 中当前选定的文本.

You can use stringByEvaulatingJavaScriptFromString to get the currently selected text in a UIWebView.

NSString *selection = [self.webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected Text" message:selection delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
[alert release], alert = nil;

这篇关于iPhone 开发:在 UIWebView 上抓取选定/突出显示的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iPhone 开发:在 UIWebView 上抓取选定/突出显示的文本

基础教程推荐