Search code examples
iosuiimageviewautolayoutstoryboardscale

Scale up UIImageView (Storyboard Autoresizing)


I have a UIImageView in a Storyboard. The image used is square. The imageView width and height are equivalent. I want to take advantage of Autoresizing in Storyboard, so that on a small device the image is scaled down and on a large device the image is scaled up. When I test on a iPhone 5 the scaling is appropriate. However, when running on a iPad the results are different. The square is stretched, and this makes sense as the dimensions of the screen is different to the dimensions of the iPhone. How can I avoid this issue, is there a process in which I can scale the view as a whole up until the height is the same as the height of an iPad and then centre the view?

Note - The image has the same width and height and the content mode is set to 'Aspect Fit'


Solution

  • Follow this procedure

    1) add a view in which all your content will be added so now you going to use 2 views NewView[with Content] and baseView

    enter image description here

    now time to add constraints to newView Do like this for leading, trailing,bottom and top [adding wr hr component]

    enter image description here

    Result For iPad

    enter image description here

    result for iPhone

    enter image description here