'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: enter image description here 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".

Example

Update:

Choose a vertical stack view, add your 4 views, mark all of them, set the constraint "equal height" and add all 3 constraints:

Step 1

Now select each constraint and set your multiplier as you like in relation to the first:

Step 2

Step 3

Step 4

Define a spacing in stack view settings:

Step 5

Define StackView border gaps relative to margin or via const value:

Step 6

You do not need more constraints. Proof by change device and orientation:

enter image description here

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.

enter image description here

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.

enter image description here

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