1

I have a requirement to allow the user to enter text in UITextView in multiple lines but when the keyboard is dismissed, we have to display the text in single line. Now, when the user taps on the UITextView,I need the text to be displayed in multiple lines again when the keyboard is in focus. I am able to achieve the first part and i am able to show the text in single line after dismissing the keyboard. But i am not able to show the text in multiple lines when the keyboard is in focus again. The text is still shown in single line when i have the keyboard in focus. I tried to change the maximum number of lines to 2 in the delegate methods but of no use.

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
textView.textContainer.maximumNumberOfLines = 2;
return YES;
}

Any suggestions? Please help.

Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75
  • First of all, you don't dismiss the **UITextView**, you dismiss the **keyboard**. Secondly, can you post the code for the transition from "multi-line"-->"single line"? My initial thought is that you'll have to have a way to undo that transition. Maybe you should keep a backing `NSString` property that contains the original text with line breaks, but you display the text with the line breaks removed when the keyboard is dismissed. You can then restore them with the original `NSString` value later. – mbm29414 Feb 09 '15 at 18:25
  • 1
    I wonder if you can animate the NSLayoutConstraints and adjust the textView dimension depending on the state. I myself have used a UIlabel that is hidden when editing in the textView otherwise it gets shown after finished editing text view text. That way textView remains single line. – Zhang Feb 10 '15 at 08:12

0 Answers0