0

i have UITextView with lines. here i added text in UITextView, while i click the next line button(return/enter) ,The text start printing before the margin .but the text should start after the margin, so i want to leave space before the text, when i entered the next line event.

Here is my code below

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{

  if ([text isEqualToString:@"\n"])
  {
     note.text=[note.text stringByAppendingString:@"           "];
  }
  NSLog(@"%@",text);
  return YES;
}
Anusha Kottiyal
  • 3,855
  • 3
  • 28
  • 45
Rajendran
  • 141
  • 3
  • 13

1 Answers1

2

Try this:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{

  if ([text isEqualToString:@"\n"])
  {
     note.text=[note.text stringByAppendingString:@"\n           "];
     return NO;
  }
  NSLog(@"%@",text);
  return YES;
}
OnkarK
  • 3,745
  • 2
  • 26
  • 33
  • You can use delegate: - (BOOL)textViewShouldBeginEditing:(UITextView *)textView – OnkarK Dec 14 '12 at 09:21
  • but when i type a word at last in a line ,if the characters exceeds then it will go before the margin only. not coming as lik that new line text position. how to solve that – Rajendran Dec 14 '12 at 09:25
  • Try to call method when you programmatically changing text of textview: - (void)textViewDidChangeSelection:(UITextView *)textView – OnkarK Dec 14 '12 at 09:31
  • couldn't get idea to do in this (void)textViewDidChangeSelection:(UITextView *)textView can u tell little briefly – Rajendran Dec 14 '12 at 10:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/21127/discussion-between-raaj-and-omk) – Rajendran Dec 14 '12 at 10:16