I have used multiplier in a place to change the view's height width depending upon the screen. And same thing happens when I used the aspect ratio as well. So, I'm lil bit confused, I can't exactly understand the difference between multiplier and aspect ratio. Can anyone explain it. And I also wanted to know about the priority constant.When should I use it?
The Aspect Ratio
is really just a convenient way to express the Multiplier
when working in Interface Builder. It effectively gets "converted" to a multiplier.
You can confirm this while debugging by inspecting the constraint's .multiplier
property. If you set a view's width to 60
, and multiplier to 1:2
(resulting in an auto-layout height of 120
), the actual value of .multiplier
will be 0.5
.
So, in my view, it depends on what feels more natural.
If I want a view to be 90% of the width of another view, I am much more likely to set the Multiplier to 0.9
--- which gives the exact same result as setting it to 9:10
.
However, if I want a view to maintain an aspect ration of, say, 3-to-2, I am much more likely to set the Multiplier to 3:2
rather than 1.5
.
Using a ratio can also be convenient when you have "non-simple" values. That is, it's easy to understand that a ratio of 3:2
is the same as 1.5
. But what if I have an image with native size of 281 x 60
, and I want to use those values to maintain ratio? 281:60
is easier to understand than .multiplier = 4.68333339691162
.
And, while they are interchangeable, it is probably a bit more intuitive to use Ratio when constraining an object to itself - e.g. I want my view's width to be 2 x its own height, so 2:1
- and using Multiplier when constraining one object to another - e.g. I want my view's width to be 75% of the width of its superview, so 0.75
.