Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView insert text in the textview text

I want to have to occasionally insert text into the UITextView text object. For example, if the user presses the "New Paragraph" button I would like to insert a double newline instead of just the standard single newline.

How can I go about such? Do i have to read the string from UITextView, mutate it, and write it back? Then how would I know where the pointer was?

Thanks

like image 803
John Smith Avatar asked May 08 '10 01:05

John Smith


1 Answers

Since the text property of UITextView is immutable, you have to create a new string and set the text property to it. NSString has an instance method (-stringByAppendingString:) for creating a new string by appending the argument to the receiver:

textView.text = [textView.text stringByAppendingString:@"\n\n"];
like image 199
Martin Gordon Avatar answered Sep 30 '22 18:09

Martin Gordon