Continuing the discussion from MyLocations: p.253 exercise aspect fill thumbnails [SOLVED]:
I took a bit of a different approach than the one by @linc.
After a bit of research, the UIImageView
has a property on it called .contentMode
. You can set this in LocationCell
, just above where you set the image property on photoImageView
.
I added the following code:
photoImageView.contentMode = .scaleAspectFill
The problem with this is that the images will extend outside the bounds of the container. In @linc 's follow up to his post, he uses .clipsToBounds
on the UIImageView property to solve the same issue he was having. So I used that method to do the same called from LocationCell
.
The final additions looked as follows:
func configure(for location: Location) {
...
photoImageView.contentMode = .scaleAspectFill
photoImageView.clipsToBounds = true
photoImageView.image = thumbnail(for: location)
}