Search code examples
interface-builderautolayoutsize-classes

What is the multiplier in Interface Builder for?


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


Solution

  • 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.