Search code examples
iosautolayoutaspect-ratio

Explain Aspect Ratio and respective terms in iOS?


I want to understand Aspect Ratio.

enter image description here

Here, I am setting Aspect Ratio of an UIImageView.

enter image description here

These are options when I click this constraint.

How this constraint works and what are "PRESETS", Reverse Multiplier and Convert to Decimal.

Thanks.


Solution

  • Aspect ratio constraint is used to control the width and height of a view as per a aspect ratio that you set here. There are some standard presets such as 1:1 which means width will be equal to height. Similarly other presets calculates the dimensions based on a ratio

    Reverse Multiplier is just used to reverse the ratio. E.g. 4:3 will be 3:4 Convert to decimal just represents the ratio as a decimal. E.g. 4:3 will be 1.33

    If you want a view to always maintain an aspect ratio then you can use this constraint. In your case if its image view and you know the aspect ratio of the image that will be set then you can set that aspect ratio as the constraint so that the image is always sized according to the image that is set to that image view,