Tony Stark Tony Stark - 1 year ago 79
Swift Question

How to expand to Labels having height in ratio 2:1

I'm new to xcode storyboard. I have a viewcontroller that contain two label of same width, but

label 1
is 80px in height and
label 2
is 40px in height.

I want those two labels to auto expand in height depending on whether they are displayed in horizontal or vertical size class, but I want
label 1
label 2
to keep their height ratio of

I know the steps to take if I wan't both labels to be the same height (control drag from one label to another, click equal height, and go to size inspector and set their content hugging priority to 200) , but I don't know the steps to take when I want the labels' height ratio to be
and to auto expand in height depending on whether it is displayed horizontally or vertically.

Could someone please kindly help me out? Thanks in advance for any suggestions!

enter image description here

I want the two labels to expand, not the numbers below the labels

Answer Source

If you want label 1 to be twice the height of label 2, then control-drag from label 1 to label 2 and select Equal Heights from the pop-up menu. Then find this constraint in the Document Outline and edit it in the Attributes Inspector on the right. Change the multiplier to 2.

Xcode demo of 2X height

If you pin the orange label to the top of the screen and pin the bottom of label 1 to the top of label 2 and pin the bottom of label 2 to the views below, then these two views will fill in the space and maintain their relative vertical sizes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download