How to get selection text from UIWebView?(如何从 UIWebView 获取选择文本?)
问题描述
,大家好.
我正在开发我的应用程序,该应用程序具有从网站发布文章的功能.
I'm developing my app which has a feature to post article from website.
这是带有 UIMenuController 的 UIWebview 的图片.
This is a picture of UIWebview with UIMenuController.
用户点击按钮时可以获得事件.但我找不到获取用户选择的文本的方法.
It was possible to get event when user tap the button. but I can't find the way to get the text the user selected.
在 UITextView 的情况下,它有 'selectedRange' 属性,因此很容易获取选择文本.
In UITextView case, it has 'selectedRange' property, so it is easy to get selection text.
UIMenuItem *facebookMenuItem = [[UIMenuItem alloc] initWithTitle:@"Facebook" action:@selector(facebookMenuItemTapped:)];
UIMenuItem *twitterMenuItem = [[UIMenuItem alloc] initWithTitle:@"Twitter" action:@selector(twitterMenuItemTapped:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObjects: facebookMenuItem, twitterMenuItem, nil];
[twitterMenuItem release];
[facebookMenuItem release];
我想在 UIWebView 上获取选择文本.有人有想法或提示吗?
I would like to get the selection text on UIWebView. Does anybody have an idea or hint?
谢谢.
推荐答案
或者,如果您不想弄乱 Javascript,您可以将所选内容复制到粘贴板,然后通过运行检索它:
Or if you donʾt want to mess with Javascript you can just copy the selection to the pasteboard and then retrieve it by running:
[[UIApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self forEvent:nil];
NSString *text = [UIPasteboard generalPasteboard].string;
这篇关于如何从 UIWebView 获取选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 UIWebView 获取选择文本?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
