UITextView获取选中的文本点
我想知道有什么方法可以获取 UITextView 中所选文本的要点吗?
谢谢!
I was wondering is there any way to get the point of the selected text in UITextView ?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 iOS5 及更高版本:现在
UITextField
和UITextView
符合UITextInput
协议,因此可以:)选择插入符号之前的最后 5 个字符像这样:
For iOS5 and above : Now
UITextField
andUITextView
conform toUITextInput
protocol so it is possible :)Selecting the last 5 characters before the caret would be like this:
是的,首先像这样获取活动选择:
myTextView.selectedRange
,然后将其传递给此方法[myTextView firstRectForRange:range]
这将为您提供第一个边界矩形(其中如果是一行,则为整个选区;如果是多行,则为第一行上的选区区域)作为CGRect
。Yes, first get the active selection like this:
myTextView.selectedRange
and then pass it to this method[myTextView firstRectForRange:range]
This will give you the first bounding rectangle (which is the entire selection if it is one line, and the area of the selection on the first line if it is multi-line) as aCGRect
.