问题描述
,大家好.
我正在开发我的应用程序,该应用程序具有从网站发布文章的功能.
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 dont 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 获取选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!