What constraints should be given to increase size of imageview with respect to device screen size without reducing image clarity
Asked Answered
D

3

1

I have to show an imageview in a universal app ans it's size should increase as the screen design in every devices without reducing image quality. The image given to the imageview is a static image. If I use static width and height constraints using size classes it will work. But I don't think it as the correct way. If i use width & height Proportional to the superview, it increases the image height but image clarity reduced in ipads. Any suggestion will be helpfull.

Dowski answered 18/4, 2016 at 17:43 Comment(2)
Use the proportional width and height constraints and make outlets to them in your code. Then you can check in your code so that the width and/or height doesn't go higher than the size of the image or get the aspect ratio out of whack.Pani
have you check my answer ?Beccafico
B
8

To make Imageviewsize respect to device for universal application , you need to give correct multipler to imageview.

please follow step to get desire output,


Step 1 :- Set Aspect Ratio to your imageview . (you can also set leading and trialing top , bottom etc. and then give aspect ratio.)

Aspect ration required to maintain to set image equal width and Height (Square)

enter image description here


Step 2 :- Set Horizontal center and vertically center imageview . (it will be differ according to your requirement , you can also take this step as step 1 and then set aspect ratio)

enter image description here


Step 3 :- Set Equal height to Superview from imageview.

(Don't panic , you will get warning to update frames or constrain but don't update it)

enter image description here


Step 4 :- Count Accurate Multiplier.

imageviewHeight / superview's height = Accurate Multipliar

Here ,

imageviewheight = 200 , superviewheight=600   so ,

200(imageviewheight)/600(superviewheight)=0.333 

(set multipler to imageview where proposanal height = superview)

enter image description here


Step 5 :- check output to different simulator.

enter image description here

I hope this detail explanation is enought to understand your question.

Beccafico answered 18/4, 2016 at 18:57 Comment(2)
exactly what i looking for. great explanation. please post auto layout constraints for other components like UIView, label and buttonBroadleaved
thank you @sushantjagtap. for increase size of UILabel size and its parent view according to UILabel text you can check this Answer. https://mcmap.net/q/23614/-adjust-uilabel-height-depending-on-the-textBeccafico
A
0

you can give equal height or width with superview with different multiplier. for example multiplier is 0.5 five then your height or width will be half of superview's height.

hope this will help :)

Asteria answered 18/4, 2016 at 17:51 Comment(0)
A
0

Anchor the edges of the image view as you want. so that the size of image view will change based on device. But set the mode of image view to "Aspect Fit" which will make sure the image will resize but maintain the aspect ratio. You can change mode in Attribute inspector.

Please refer Difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill?

Apocynthion answered 18/4, 2016 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.