Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the multiplier in Interface Builder for?

What does the multiplier, which is a property of a constraint in Auto Layout, do?

like image 263
Cesare Avatar asked Dec 28 '25 19:12

Cesare


2 Answers

The relationship between two values in a constraint is determined by a formula:

 b = am + c

where a and b are the two values that are to be related, m is the multiplier, and c is the constant.

So for example if one width is to be twice that of another, clearly a multiplier of 2 is going to make sense (and a constant of 0). But if one width is to be 10 more than another, then a constant of 10 is going to make sense (and a multiplier of 1).

The default, obviously, is the multiplier is 1 and the constant is 0. That makes a and b equal.

Extra for experts: Under the hood, part of the reason for the structure of this formula is that you end up with a set of simultaneous linear equations to solve for. This is how the various constraints are resolved to get the actual layout.

like image 147
matt Avatar answered Dec 30 '25 20:12

matt


According to Apple's docs: "The constant multiplied with the attribute on the right-hand side of the constraint as part of getting the modified attribute."

It is useful, for instance, if you want one view's height to be 35% of another view's height. In this case, you'd create a constraint making their heights equal with a multiplier of 0.35.

like image 29
vacawama Avatar answered Dec 30 '25 20:12

vacawama