8

I have some code:

CGRect currentFrame = textLabel.frame;
CGSize max = CGSizeMake(textLabel.frame.size.width, 3000);
CGSize expected = [[textLabel text] sizeWithFont:textLabel.font constrainedToSize:max lineBreakMode:textLabel.lineBreakMode];
currentFrame.size.height = expected.height;
textLabel.frame = currentFrame;

expected.height = expected.height + 70;

[scrollView setContentSize:expected];

textLabel placed inside UIScrollView to display multiline text information.

In older version of application, without 4-inch screen support, everything was perfect. But now, unfortunately, resizing UILabel does not work.

Maybe, somebody can advice me, what should I change?

Thanks.

Andrey
  • 2,659
  • 4
  • 29
  • 54

1 Answers1

27

When using AutoLayout you should not update the frame property, instead modify the contraints on a view.

On the other hand, you could also let AutoLayout work for you. Make sure the numberOfLines property of the label is set to 0 and the height constraint is of type Greater Than or Equal (>=). This way the layout will update automatically after setting new text on a label.

Joris Kluivers
  • 11,894
  • 2
  • 48
  • 47