This is not a duplicate of this question.
Below you'll see a grid of rectangles with 3 columns. I'm trying to achieve the same effect but with images. The images should be clipped, but otherwise not appear stretched or distorted.
Here's how I achieved the rectangle grid...
// In my view struct...
private let threeColumnGrid = [
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
GridItem(.flexible(minimum: 40)),
]
// In my body...
LazyVGrid(columns: threeColumnGrid, alignment: .center) {
ForEach(model.imageNames, id: \.self) { imageName in
Rectangle()
.foregroundColor(.red)
.aspectRatio(1, contentMode: .fit)
}
}
This is the layout I want using Rectangles...
This is my goal...
Update:
If I do this...
Image(item)
.resizable()
.aspectRatio(1, contentMode: .fit)
The images distort if their aspect ratio wasn't already 1:1. For example, the circle image in the screenshot below should be a perfect circle.