Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constrain for uiimageview to keep aspect ratio and expand based on device size

i have this problem in 2 projects.Normally, profile image is displayed in circle like

enter image description here

and this is ok for iphone5 size.problem raises on bigger devices.like

enter image description here

as you can see size of profile imageview, it looks small compare to cover image.if i let it increase based on outer image then xocde ignores the aspect ratio constrains which results in non cricular profile imageview

here's current constrains image

enter image description here

any suggestion how should i handle it?

Update here's result if i set constrain on profile imageview to increase with ratio to background image.

enter image description here

asks for y of image view,as i want it to be center so i sets fixed hight = 68 in hopes that xcode will break this constrain to keep aspect ratio, result

enter image description here

so if i remove hight = 68 and add constrain like width.

enter image description here

result

enter image description here

like image 691
Sameer Azeem Avatar asked Sep 13 '17 10:09

Sameer Azeem


People also ask

Does Uiimageview have intrinsic content size?

A vanilla UIView instance, for example, does not have an intrinsic content size. This means that you need to add four explicit constraints to describe the size and position of a UIView instance in a user interface.

What is a 2 3 aspect ratio?

2:3 Aspect Ratio. 2:3 is the most popular aspect ratio for printing. Print sizes that are a 2:3 aspect ratio and are popular with poster, canvas, and decal printing are 24 x 36 inches and 40 x 60 inches.

What is the difference between aspect fill and aspect fit when displaying an image?

When you Fit an image, the frame will fit the image, keeping its original aspect ratio. When you Fill an image, the image will crop to fill the frame.


1 Answers

Select your image view and it's super view together and give equal width constraint,

then select that equal width constraint from size inspector, and reduce its multiplier until you get your desired width!

Now select your image view and give aspect ratio constraint!

And finally give position constraint for x and y position!

In your case center x and center y with it's super view I think!

And your imageview will increase or decrease with device width and will remains square always!

And You should set dynamic corner radius(half of width or height of your imageview) in layoutSubviews method of tableviewcell's class as you need rounded imageview and your size is dynamic!

like image 85
Ketan Parmar Avatar answered Nov 15 '22 04:11

Ketan Parmar