Anton Chuiko
Anton Chuiko

Reputation: 245

UIImageView does not stretch to whole screen

I prototype an app and navigation and my UIImageView in ViewControllers, which I created in Storyboard (Xcode 6) does not stretch to full screen. For example, I have UIImageView with 640×1136 image. If I run it on iPhone 5, it shows me full screen. But if I run it on iPhone 6 or 6 Plus, it locates in top left corner. I read so many topics and articles, but nothing helped.

enter image description here

enter image description here

Upvotes: 2

Views: 5923

Answers (3)

parvind
parvind

Reputation: 907

use AutoLayout and add all four constraint(top right,left,bottom) on it.

Upvotes: 0

Ehab Alsharkawy
Ehab Alsharkawy

Reputation: 44

Just add aspectRatio constraint to imageView

Upvotes: 2

Chase
Chase

Reputation: 2304

Make sure your UIImage is in an UIImageView and then either add constraints or change the content mode like this:

myImageView.contentMode = UIViewContentModeScaleAspectFit;

Or change it in the story board in the attributes inspector under view.

Here is a list of all the values you can set for this property.

Edit: reading your issue over, I think you definitely need to add constraints to your view. There are lots of tutorials on how to do this: here is apples.

You add your constraints by clicking the pin menu, and then clicking on the four red brackets and clicking "Add Constraints".

enter image description here

Upvotes: 6

Related Questions