0

I searched the web but could not find an acceptable solution to my problem. So, basically I have a UITextView in my project and I want the user to only be able to put in 2 lines of text. If the text has reached the 2 lines than it should not let the user put in anything more. (Exactly like in Snapchat but with 2 lines instead of one). I have some code which basically does what I want but instead of stopping the user from putting in more text it just puts periods to the end of the text.

self.textView.textContainer.maximumNumberOfLines = 2;
self.textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;

I thought that maybe there is an option to achieve this in the NSLineBreakBy object but unfortunately there is not.

Any ideas on how could I do this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Balázs Vincze
  • 357
  • 1
  • 3
  • 14

1 Answers1

1

If the text has reached the 2 lines than it should not let the user put in anything more.

You could implement the delegate method textView:shouldChangeTextInRange:replacementText: such that you don't allow a return if the text already has two lines.

Caleb
  • 124,013
  • 19
  • 183
  • 272