Reputation: 2437
I create an instance of UITextView programmatically. I want to assign some text to particular line in UITextView programmatically. Here is my code to create UITextView.
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
[textView setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:textView];
For example I want to add some text to particular line (at the end of line 5).
Programmatically, how is it possible to do this?
Upvotes: 0
Views: 1740
Reputation: 1948
you can use the following:
NSString *str=yourTextview.text;
[str stringByAppendingString:yourNewString];
Then add it to textview
yourTextView.text=str;
check it and let me know if any clarification you need
Upvotes: 1
Reputation: 4552
You can't edit lines directly in the text view because the number of lines depends on the content size and the size of the font.
Check this question as a reference: How to Read Number of lines in UITextView
You could do some calculation to determine where to insert the text, but I'm nor sure if that's the best way to go around. There is probably a better way to accomplish what you are trying to do.
Upvotes: 1
Reputation: 6899
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
textView.text = @"xxxxxx";
...
Upvotes: 4