Proportional distance constraints in layout

I cannot achieve the desired layout of the views using the automatic layout in> iOS6.

I have UIView1 and UIView3 that are attached to the parent view (respectively with TopSpaceToSuperview, BottomSpaceToSuperView and FixedHeight), and they behave as expected when the parent view changes height.

What restrictions should be specified in IB for UIView2 if I want it to maintain the same proportional distance to its siblings (UIView1 and UIView3) when the parent view changes height? (as shown in the image)

resizing the parent view

+4
source share
1 answer

The way to do this is to use invisible "spacer" views between your views.

You cannot have spaces with a relatively large size, so use these views.

If current spaces place a UIView in each.

Then (in code, since you cannot do this in IB), set a height limit between them with the desired multiplier you want.

i.e.

[NSLayoutConstraint constraintWithItem1:spacer2 attribute:NSLayoutAttributeHeight relation:NSLayoutRelationEqual item2:spacer1 attribute:NSLayoutAttributeHeight multiplier:0.5 constant:0]; 

Then make the other representations β€œpasted” over and under these spacers with an interval of 0.

Then you just need to hide these views, and the machine will take care of everyone else.

+8
source

Source: https://habr.com/ru/post/1492043/


All Articles