0
votes

This is the current setup I'm using. In my storyboard I have a ViewController with a UIScrollVIew that is position and sized with Autolayout.

enter image description here

The content of the scrollView is added programatically based on UIView built in interface builder. It has several labels, all of them using autolayout: leading and trailing to superview, and vertical spaces. enter image description here

The scrollview gets resized accordingly to the screen size(iPhone / iPad), but the contentView's width is always the one specified in interface builder. I've tried setting contentview's frame width to match the scrollview frame width, and that changes it's frame but the labels width stay exactly the same. Also when I start to scroll it reverts my frame change. Any ideas how I can make the content's width match the scrollview's and update it's content accordingly?

I'm also adding constanints from the contentView to the scrollView programatically:

[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollContent]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollContent]|" options:0 metrics: 0 views:viewsDictionary]];
1

1 Answers

0
votes

Setting the frame's width didn't work but apparently making a width constraint did the trick. Not sure why but maybe it helps other people as well.