Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deselect text in UITextView?

Tags:

ios

uitextview

After some moment I need deselect text in UITextView. How do I deselect text in UITextView?

enter image description here

EDIT: I need to do programmatically.

like image 917
Voloda2 Avatar asked Feb 21 '12 07:02

Voloda2


2 Answers

UITextView adopts the UITextInput protocol, which has a selectedTextRange property. Set the property to nil:

self.textView.selectedTextRange = nil;
like image 186
rob mayoff Avatar answered Oct 18 '22 01:10

rob mayoff


This is the way it works and you can touch wherever you want in the view in order to deselect the previously selected text:

On your UIViewController write this function:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    self.view.endEditing(true)
}
like image 3
Alex Zanfir Avatar answered Oct 17 '22 23:10

Alex Zanfir