0
votes

I have laid out all the containerViews and subviews in my scrollView in the storyboard, each with a top, bottom, leading and trailing pin, and also a height and a vertical spacing constraint. After I load my info from the server and populate the info into my UILabels, I make all my UILabel (with numberOfLines=0) call sizeToFit. I then reset all my container view's height accordingly and finally resetting also the height of my scrollView and its contentView.

However, when I run the program, the scrollView did not expand vertically as expected. I made an NSLog querying the frame.size.height of all my UILabels and they are correctly expanded. But not the scrollView and the containerViews for the UILabels.

Do I have to call some methods to ask the app to re-layout the views and subviews according to the new height constraints? And what is that magic method?

Need help!

1
After setting up your view did you call [self.view layoutIfNeeded] ??Jad Feitrouni
Showing your code might help. How do you set up the scrollView?CaptJak

1 Answers

1
votes

The content size of the scroll view needs to exceed the size of the view's frame. From the Apple Docs:

The UIScrollView class provides support for displaying content that is larger than the size of the application’s window.

If you need to set the size of the scroll view, you can simply set the content size programmatically, depending on the number of elements (in your case UILabels).

Quick and dirty:

[self.scrollView setContentSize:CGSizeMake(yourScrollViewWidth, theLabelheight * yourArrayOfObjects.count)];

Just keep in mind that doing it like this will not adjust with rotation or any other AutoLayout magic.