Explain Aspect Ratio and respective terms in iOS?
Asked Answered
C

3

15

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.

Crenulation answered 2/2, 2016 at 6:41 Comment(0)
A
15

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,

Advertence answered 2/2, 2016 at 6:48 Comment(6)
Pretty good, dear, So, where we can use such aspects and what is advantage?Crenulation
Where you can use depends on your UI requirements. If you want to maintain a view size as per a particular ratio then you can use it without having to calculate the dimensions on your own. For e.g. if you want a view to always be a square then you can use the 1:1 ratio. If you want your view to have aspect ration of 4:3 then you can use that as the ratio. In general if your view's one dimension (width or height) is a factor of the other dimension (height or width) then you can use this constraint.Advertence
It means if I set Top and Leading and give Aspect Ratio, it will fulfill basic X Y and W and H Constraints. Am I right ?Crenulation
Yes, but you still have to set one of the W or H values. Depending on the aspect ratio the other dimension will be calculated.Advertence
one last Q, If I am using Image and Label, do I need to give fixed height or width or not. What about how to use aspect ratio in these two UI elements.Crenulation
How do you want to layout the image and label? Will the label overlay on top of the image aligned to the bottom of the image view? If so then you can set a fixed height for the label and set the width constraint of the label to the width constraint of the image view. So whenever the image view's width changes the label width also changes equally.Advertence
C
3

If you select Aspect Ratio for a single item, the width of the item is used as the numerator for the ratio, and the height is used for the denominator. If you select Aspect Ratio for multiple items, Auto Layout chooses the width of one of the items for the numerator and the height of another item for the denominator. To change the initial aspect ratio, edit the Multiplier field of the Attributes inspector for the constraint. To change which item to use for the width or the height, use the First Item and Second Item pop-up menus in the Attributes inspector.

Read more here

Corri answered 2/2, 2016 at 6:48 Comment(0)
J
1

Constraints are something like equations in maths.

Ex:

let

X- known value (20)

Y- Unknown value (?)

m- multiplier (like 2 or 3 times)

C- constant (+3 or -3)

to find Y value we use this equation.

Y = m * X + C

Y = 2 * 20 + 3

Y = 43

Constraint equation:

First Object = (Multipler * Second Object ) + constant

width = (0.5 * Height) + 20

In Aspect Ratio condition

Note : one value should be fixed ( Height or width )

A) PRESETS

1)Width = 1 * Height

Width/ Height = 1/1 (1:1)

2)Width = 3/4 * height

Width / Height = 3 / 4 (3:4)

B) REVERSE MULTIPLIER

Before Reverse

Width = 1/2 * Height (1:2)

After Reverse

Width = 2/1 * Height (2:1)

C) CONVERT TO DECIMAL

Before conversion

Width = 1/2 * Height

After Conversion

Width = 0.5 * Height (0.5)

Jurist answered 2/2, 2016 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.