0

i want only 3 lines in UITextView. And each line will have maximum 29 characters

What i did is

 static const NSUInteger MAX_NUMBER_OF_LINES_ALLOWED = 3;

        NSMutableString *t = [NSMutableString stringWithString: self.addressTextView.text];
        [t replaceCharactersInRange: range withString: text];

        NSUInteger numberOfLines = 0;
        for (NSUInteger i = 0; i < t.length; i++) {
            if ([[NSCharacterSet newlineCharacterSet] characterIsMember: [t characterAtIndex: i]]) {
                numberOfLines++;
            }
        }

        return (numberOfLines < MAX_NUMBER_OF_LINES_ALLOWED);

In below delegate method

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

Please let me know that how i can restrict length of each line to max 29 characters.

That is if user type 29 characters in first line then take him to newline.

Thanks in Advance.

Nik
  • 1,679
  • 1
  • 20
  • 36
  • see this link may be helps you http://stackoverflow.com/questions/27475670/every-new-line-add-a-numbered-list-uitextview – Anbu.Karthik Oct 14 '15 at 08:01

1 Answers1

0

If i understand you right. You need implement next few lines in shouldChangeTextInRange: method.

if (range. location%29==0) {
//add new line
}

I hope, it will help you!