Can anyone explain here about multiplier and constant in autolayout. How to work they in autolayout and what are the purposes and how to use both of this in autolayout in simple terms.
A constraint has a first item (one view) and its attribute (leading or trailing edge for example) a relationship (usually of equality) and optionally a second item and its attribute, this is missing if you want to specify width or height of a view in an absolute way and not relatively to another view. These elements are put together with a multiplier and a constant to give a linear equation:
item1.attribute1 = multiplier × item2.attribute2 + constant
Items frames will be changed by Autolayout to satisfy all of the equations generated by the constraints.
NSLayoutConstraint Reference
Pretty cool question Darshan,
Constant
In simple term Constant is actual value in double format. Just like if you make constraint for vertical space b/w two uiviews and the distance for 2 views are 20 then the value of constant is 20.
You also can make IBOutlet of constraint and change value of constrains programmatically based on different devices.
Multiplier
Multiplier works on 2 objects.
For example if you have 2 uiviews (A, B) and you want to make
B's Height = A's Height / 2 [half of A's Height]
then you have to make constraints for
B's Height = A's Height
then
Select constraints from Size Inspector and make
Multiplier value = 0.5
There are many blog and forums that describes deeply. I have just given simple idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With