I'm just to create an image that spans the entire screens width. The image is a square (512x512) and the idea is to scale to the width of the device while maintaining aspect ratio. I've tried doing this with contraints, setting the margins to left: 0, top: 0, right: 0
and keeping the image at aspect-fill
. The issue however, is that the image is becoming larger than the screens width, and thus the image is not only being cut off on the left and right, but is much taller than it should be.
How can I properly size an image to have the same width/height has the width of the device?
The problem is you didn't set constraints on the image view. Set the following constraints on image view:
1) Set width of image view equal to width of self.view
2) Set aspect ratio 1:1 // This makes sure your image's height is equal to width
You would need additional constraints to specify the x and y position of the image view.
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