0

This SO answer suggests ways to make a textView adjust to the quantity of text. The accepted answer does not work for me and I am thinking it may have to do with the fact that I created the textView in storyboard. Does anyone know of a way to adjust the textview to lines of content when using storyboard?

Note: I noticed examining the file inspector in Storyboard that auto layout is on by default. However, when I went to change this it gave me warnings regarding affect on other device types so I am reluctant to change this default.

code from linked to answer:

- (void)textViewDidChange:(UITextView *)textView
{
    CGFloat fixedWidth = textView.frame.size.width;
    CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
    CGRect newFrame = textView.frame;
    newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
    textView.frame = newFrame;
}

Thanks for any suggestions.

Community
  • 1
  • 1
user1904273
  • 4,562
  • 11
  • 45
  • 96
  • Use autolayout constraints to change the height of textView (programmatically) – nikhil84 Jan 04 '16 at 12:49
  • how would I do that? – user1904273 Jan 04 '16 at 12:51
  • 1
    It should not matter that the `UITextView` was created in a storyboard. Can you verify that your `textViewDidChange:` method is called? If not, make sure you are setting the text view's delegate to the class with that method in it. However, if you are using AutoLayout constraints already, it would probably be better to create a height constraint for the field, bind it to an IBOutlet, and change it programmatically instead of altering the frame, as @nikhil84 said. That way your other views will change accordingly too. – Eric Galluzzo Jan 04 '16 at 13:19
  • 1
    If you want to use auto layout you shouldn't adjust the frame manually. Look at the same question but the answer you want is the second one, the top voted, non-accepted answer. – Stephen Darlington Jan 04 '16 at 15:03

0 Answers0