I'm actually facing difficulties to make my UIScrollView
fully responsive using only storyboard constraints.
Here is my hierarchy :
> - UIViewController
> - UIView
> - UIScrollView
> - contentView
> - module1View
> - module2View
> - module3View
All the modules are used to display charts. I want them to be responsive. I want their width to be 100% of the screen and their height is defined by a ratio added using constraint. The modules are displayed next to each other like news in a newsfeed.
My question is : How do you set the contentView
height equal to the sum of all the modules (module 1 + 2 + 3) ?
In other word I want to achieve :
- Top of contentView = top of module 1
- Top of module 2 = bottom of module 1
- Top of module 2 = bottom of module 2
- Bottom of contentView = bottom of module 3
To managed to do that I follow some tutorial found on internet. Here are the steps I followed :
- Setting
UIScrollView
contraints to define its place and position. - Setting
UIScrollView
top, bottom, left and right spacing to nearest neighbour to 0. - Setting the constraint between modules to "stack" them one on an other.
- (I'M BLOCKED HERE) Setting the bottom of the
contentView
to the bottom of module 3 to allow theUIScrollview
to scroll until the end content.
I tried to force the height of UIScrollView
: It works but it's not responsive. As the height of the module is calculated through a ratio, depending on the device, the height "module 1 + 2 + 3" while change.
I tried to add a constraint from module 3 to contentView
to set the bottom of module 3 = bottom of contentView
. All the constraints turn red with warning everywhere.
Do you have any idea to how to set height of contentView
based on a responsive content ? (Like "wrap-content in a way).
Thanks in advance for you help !
mainContentView.frame = CGRectMake(0, 0, self.view.width, module1View.height+module2View.height+module3View.height);
in ViewDidLoad and viewWillAppear, none of them worked – Nickel