In my app, I'm trying to get images from my Instagram account and render them in a collection view. When using
self.imageView.contentMode = .scaleAspectFit
self.imageView.clipsToBounds = false
The images scale perfectly. But since the images from the Instagram feed are of different sizes, the images in the collection view are of different sizes. A few are perfect squares, a few are smaller, and a few are rectangles.
I want to have a collection view of images all perfectly of the same size (square in shape) and images maintaining their aspect ratio. How can I go about this?
Thanks in advance.
To show the full photo and maintain aspect ratio, set contentMode = .scaleAspectFit
.
To fill the square imageView
but show the photo with the correct aspect ratio set contentMode = .scaleAspectFill
and clipsToBounds = true
.