Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autolayout aspect ratio for UIImageView / UIView

How to set autolayout for UIImageView /UIView so that the image view width and height increases a bit for iphone 6 and 6 plus. I have tried adding the constraint Aspect ratio but the increased height and width are very big. Is there anyway to set the constraint height and width of image view can be set manually for iphone 6 and 6 plus. Take a look at the screenshot the image view in iphone 6 and 6 plus should be little smaller than it is showing now. enter image description here

like image 972
abdul sathar Avatar asked Jan 02 '15 13:01

abdul sathar


People also ask

What is Autolayout aspect ratio?

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.

Does UIImageView have intrinsic content size?

Here is the essential problem: the only way in which UIImageView interacts with Auto Layout is via its intrinsicContentSize property. That property provides the intrinsic size of the image itself, and nothing more.

What is aspect ratio in Swift IOS?

aspectRatio(16/9, contentMode: . fit) , the aspect ratio implementation takes the proposed size, and proposes a new size to its child. When the content mode is . fit , it fits a rectangle with the desired aspect ratio inside the proposed size.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .


1 Answers

As I understood your problem is that you want to control how much the image will be increased in each different screen size. You can control everything. What you need to do is to assign an equals width constraint on your image. Preferable on image's width. The relation will be with the superview and then you can change the relation by adding your own Multiplier.

What you need to do exactly:

1) Select your image view.

2) Hold down the control key. While you are holding it, drag your mouse from the image view to the outer view.

3) Select 'Equals width'.

4) Double click on your constraint in the 'Constraints' tab.

5) Ensure that the image view is presented as the first item, if not click on the first item and select 'Reverse first and second item'.

6) Play with the multiplier until you are satisfied with the result on the preview screen.

like image 98
Tzegenos Avatar answered Oct 13 '22 02:10

Tzegenos