Auto-layout limitation: when resizing, does it distribute space unevenly in sub-items?

The easiest way to demonstrate my question is with an example, so here it is:

I have a container view that has two subsets, A and B.

Container: 240x80

A: 80x80, fixed distance between leading / upper / lower.

B: 160x80, fixed distance between leading / upper / lower, distance between points h with A.

enter image description here

Now, when I resize the container to, say, 480x80, I have something like this: enter image description here

This is because Xcode considers my limitations to be ambiguous, so it bound the width for me and gives all the extra horizontal space for B.

Well, I understand his concern, but what I really want is to resize A and B proportionally as follows:

enter image description here

My guess is that it will have something to do with the Hugging / compression priority settings, but I cannot figure out how to set these values ​​to get the desired results!

To ask this question in another way, when the container is enlarged, how to indicate where the extra space goes? How to set priorities so that the space is distributed for viewing A and viewing B 4: 6? 5: 5? 8: 2

?

Thanks!

+4
source share
2 answers

This is very similar to the other question you just asked. Make a constraint that makes the width of one view equal to another with a multiplier to get the desired ratio:

NSLayoutConstraint *con = [NSLayoutConstraint constraintWithItem:self.viewA attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.viewB attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0]; 

This restriction must be added to the supervisor of representations A and B.

+6
source

Not that the answer provided was unworthy, but you should do it now in Xcode (5.1.1) by creating a width limit between view A and view B and setting a multiplier.

To do this, remove any other width constraints that may exist between the two views, then drag from view A to view B and select an equal width constraint. Select this restriction in the Document Structure view, and then in the inspector change the coefficient to the desired coefficient. In your case, it looks like it could be 1: 3, or something like that. Here's what my look looks like:

enter image description here

And what the inspector should look like:

enter image description here

Just play with the odds until you get it right.

+4
source

All Articles