This is my first app from scratch under iOS 8 and XCode 6, so these spacing issues have been killing me. In the below you can see I have an UIImageView that I want to be a square, but I want it to stretch across the width of the screen as well.It has a width and height value so when the app runs the screen is wider so it ends up a tiny box in the top left corner. I've tried messing around with the constraints in every way I could think of, but when I constrain it the image blows up to full size and covers everything going off the screen. How do I get it to stretch and keep the 1 to 1 aspect ratio?
EDIT Ok, I was wrong. It's not the UIImageView that's not adjusting, it's the entire view.
If you are resizing UIImageView manually, set the content mode to UIViewContentModeScaleAspectFill . If you want to keep content mode UIViewContentModeScaleAspectFit do not resize imageview to 313. Image will adjust maximum possible width and height , keeping it's aspect ratio.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
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.
As another example, a portrait-style image might have a ratio of 2:3. With this aspect ratio, the height is 1.5 times longer than the width. So the image could be 500px × 750px, 1500px × 2250px, etc.
Constrain both sides and top to superview. You can also say that, for example, width/height can be >= 320, which sometimes helps. But remember, it will only work in portrait, when you turn the UI to landscape, the image can never stay square while filling the width and being fully onscreen at the same time.
EDIT: the image should not try to stretch beyond screen bounds (in portrait) as long as you do not tell it that it should be "this far from the bottom"
EDIT - 2: Set the background view constraints to superview. all 4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With