0

I'm working with a LazyVGrid with SwiftUI to display 8 images.

As you can see from the photo, the dimensions of the images are not uniform, some are exact, others have a lower height than the next photo ..

enter image description here

I don't understand why this happens .. Do you have any ideas to solve the problem?

This is how I created the LazyVGrid

LazyVGrid(columns: [GridItem(.adaptive(minimum: 160), spacing: 10)], spacing: 20) {
                
       ForEach(productsItems) { product in
           VStack {
              Image(product.image)
              .resizable()
              .scaledToFill()
              .cornerRadius(5)
              .padding(5)
              .background(
                   RoundedRectangle(cornerRadius: 5)
                   .stroke(.gray, lineWidth: 0.5)
              )
        }
     }
 }
kAiN
  • 2,559
  • 1
  • 26
  • 54

1 Answers1

0

It looks like the images have different aspect ratios, so if they scale to the same width the height is different. If you want all images cropped in the same aspect ratio, you can follow this approach: Clip image to square in SwiftUI

ChrisR
  • 9,523
  • 1
  • 8
  • 26