'Constraint "equal heights" for views of different sizes in iOS?
I saw a lot of similar questions but they are all for situations with equal views.
In my case I have a vertical stack of views: And they should keep proportions simultaneously on different devices.
Could you advice how to achieve such goal? Xib or programmatically - it makes no odds.
Currently I'm trying to set their sizes manually.
Solution 1:[1]
Define equal height constraint, than edit it and set multiplier to e.g. "1:5".
Update:
Choose a vertical stack view, add your 4 views, mark all of them, set the constraint "equal height" and add all 3 constraints:
Now select each constraint and set your multiplier as you like in relation to the first:
Define a spacing in stack view settings:
Define StackView border gaps relative to margin or via const value:
You do not need more constraints. Proof by change device and orientation:
Solution 2:[2]
The Above answer is fine, but I am adding one more way to use equal heights without using stack view.
add a number of views you want on the main view.
Give Top, Leading, Trailing Constraints zero to 1st, 2nd, 3rd view and give Leading, Trailing, bottom Constraints zero to the last view.
Now ctrl + drag from 1st view to second view and give Equal heights and vertical space. Repeat these steps for 2nd to 3rd and 3rd to 4th view.
Then select all height constraints one by one and set the multiplier to 1 to get equal height views.
play with multipliers to change views heights.
Thanks :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |