开发者

Grab SELECTED text on UITextView

开发者 https://www.devze.com 2022-12-27 07:19 出处:网络
How do I grab the SELECTED or HIGHLIGHTED text on a UITextView?I already know how to do this on UIWebView using JavaScript.Now I am trying to 开发者_开发知识库figure it out for the UITextView.you can

How do I grab the SELECTED or HIGHLIGHTED text on a UITextView? I already know how to do this on UIWebView using JavaScript. Now I am trying to 开发者_开发知识库figure it out for the UITextView.


you can do it by

NSRange range = [txtView selectedRange];
NSString *str = [txtView.text substringWithRange:range];


Swift 3.0

In Swift, getting the selected text from a UITextView is done by first getting the selected text range (a UITextRange), and then using that range to get the actual text:

if let textRange = myTextView.selectedTextRange {
    let selectedText = myTextView.text(in: textRange)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号