0

I have view simmilar to this below:

Views stack

How can I make it possible to make height of first and last view bigger proportionally, when making yellow view height smaller? Can I do it by setting content hugging priority and content compression?

  • Maybe [this](http://stackoverflow.com/questions/29562015/auto-layout-proportionally-scaling-views) helps you? – Reinhard Männer Feb 22 '17 at 19:15
  • Not exactly. I don't want to have this views same height. I want to grow both views, while this yellow one is getting smaller. I can only create situation when only one view is growing, when this yellow one is getting smaller. But I want, something like, divide the space left by yellow view into the two pieces, and add this values to height of first and last view. – michaltalaga Feb 22 '17 at 19:20
  • I do not unterstand your problem: In your example, you have 4 views. From top down: violet, label, yellow and button. What do you mean by "both views"?. Which "one view is growing, when this yellow one is getting smaller"? What is the "first and last view"? – Reinhard Männer Feb 22 '17 at 19:26
  • First view is violet, last view is button. When the yellow view is getting smaller, I want to both violet and button get bigger. Now I'm in a point when if the yellow view is getting smaller, only button is getting bigger. That is my problem. – michaltalaga Feb 22 '17 at 19:29
  • So I assume, the height of the label should remain the same. Do you assign the layout constraints in Interface Builder or in code? – Reinhard Männer Feb 22 '17 at 19:35
  • Yes, exactly. I'm assigning them in Interface Builder. – michaltalaga Feb 22 '17 at 19:37
  • ...and how is the height of the yellow view made smaller? Is this done at compile time or in real time? – Reinhard Männer Feb 22 '17 at 19:43
  • It is done in real time - let say, if I click on the button, the yellow height is set to 0. – michaltalaga Feb 22 '17 at 19:52

1 Answers1

0

Now that I apparently understand your problem, I suggest the following:

  • The top of the violet view has to be set equal to the top of the superview.
  • The height of the violet view is still undefined.
  • The bottom of you violet view has to be set equal to the top of the label.
  • The label has a fixed height.
  • The bottom of the label has to be equal to the top of the yellow view.
  • The yellow view has initially a fixed height.
  • The bottom of the yellow view has to be set equal to the top of the button.
  • The height of the button is still undefined.
  • The bottom of the button has to be set equal to the bottom of the superview.

This leaves the heights of the violet view and the button undefined. But your requirement is that their heights are proportional.
This can be achieved be setting them first to be equal to each other. Then double click the constrains and change the multipliers, e.g. make the multiplier of the violet view larger, and the multiplier of the button smaller.
Then you have an unbroken chain of vertical constraints, and auto layout should work correctly if you assign a height of 0 to your yellow view.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116