Reputation: 1485
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
.
Upvotes: 8
Views: 5451
Reputation: 8995
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)
}
Upvotes: 6
Reputation: 13833
you can do it by
NSRange range = [txtView selectedRange];
NSString *str = [txtView.text substringWithRange:range];
Upvotes: 12