gpt4 book ai didi

iPhone开发: Grabbing selected/highlighted text on UIWebView

转载 作者:行者123 更新时间:2023-12-03 18:34:38 25 4
gpt4 key购买 nike

问候,

请告知我如何才能在 UIWebVIew 上获取所选文本。

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

Selection and Menu Management

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.

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

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

亲切的问候,欧诺

最佳答案

您可以使用stringByEvaulatingJavaScriptFromString获取 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开发: Grabbing selected/highlighted text on UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1968872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com