显示 UIMenuController 时获取选定的文本
当用户在 UITextView 或 UIWebView 中选择某些文本时,将显示 UIMenuController。有没有办法以编程方式访问这个选定的文本?
我需要它,因为我想将自定义项目添加到 UIMenuController:“搜索”选项,该选项将用于搜索数据库中的选定文本。
是否可以不使用“复制”项将文本复制到粘贴板,然后下次从 UIPasteBoard 获取它? - 我对这种解决方法不感兴趣。
When the user selects some text in UITextView or UIWebView, UIMenuController is shown. Is there any way to access this selected text programmitically?
I need it because I want to add custom item to UIMenuController: 'Search' option which will be intended to search for selected text in database.
Is it possible without using 'Copy' item in order to copy the text to pasteboard and then getting it from UIPasteBoard with the next time? - I am not interested in such workaround.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我所做的就是将此方法添加到 UIWebView 的类别中:
之后,我可以使用
[webView selectedText]
访问当前选择。What I did was to add this method to a UIWebView's category:
After that, I can use
[webView selectedText]
to access the current selection.您是否看过Apple的文档。您可以使用提供的MenuItems属性来创建自定义UIMenuController。看看下面的图片
并按照此
详细信息链接。
您还可以查看 Apple 提供的示例代码来了解该功能。
http:// /developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139
在此示例代码中,他们在 UIMenuController 中显示“电子邮件”。
所以继续编码...祝一切顺利...
干杯
Did you have a look at Apple's documentation.You can use the MenuItems property provided to create your custom UIMenuController.Have a look at the image below
and follow this
link for details.
You can also have a look at the sample code provided by Apple to understand that feature.
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010139
In this sample code they have show "Email" in the UIMenuController.
So go ahead and code...All the best...
Cheers
要从 UIWebView 中显示的 PDF 中抓取文本,这将起作用
To grab text from a PDF displayed in a UIWebView this will work