iPhone Development: Grabbing selected/highlighted text on 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 上抓取选定/突出显示的文本


基础教程推荐
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01