1

I have 2 views, yellow & green. I want the yellow view to take up 70% of the space and green 30%, so 70:30. I embedded both in a stack view and gave the stackview constraints, bottom, left, right and height. I want to achieve the yellow box taking 70% of the space in the stack no matter the screen, how may I do so?. I have tried to give the yellow a constant of width, but that doesnt turn out so nice on all iPhones, only on a few does it look alright. stack view image for project. My app is going to be run in landscape mode only

  • 1
    Content Hugging Priority seems irrelevant here. You just need to add an "Equal Widths" constraint. – Sweeper Jun 11 '21 at 08:06
  • I added equal widths in the following ways: 1] yellow equal width to stack, 2] yellow equal width to green, 3] green equal width to stack but they all give errors. Perhaps I am not doing it correctly, can you elaborate? I am trying to achieve the look in the image I attached. – Shehryar Ahmad Rajput Jun 11 '21 at 08:13
  • Look at the answer. That's basically what I mean. I don't think you even need a stack view. – Sweeper Jun 11 '21 at 08:15

1 Answers1

2

Select yellow & green views you want to arrange and add a new 'Equal Widths' constraint. After that, go to 'Size Inspector' and change the 'Multiplier' value to 0.3 (30%). Be sure that you have set UIStackView's 'Alignment' and 'Distribution' to 'Fill'.

Example:

enter image description here

Burak Akkaş
  • 486
  • 3
  • 8