Search code examples
iphoneobjective-cuitextviewuitextviewdelegate

UItextView Space on nextline event


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;
}

Solution

  • 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;
    }