【问题标题】:Uniform size of images inside a LazyVGridLazyVGrid 中图像的统一大小
【发布时间】:2022-01-25 00:22:42
【问题描述】:

我正在使用 LazyVGridSwiftUI显示 8 张图片

从照片中可以看出,图像的尺寸并不统一,有些是精确的,有些比下一张照片的高度低..

我不明白为什么会发生这种情况..您有解决问题的想法吗?

这就是我创建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)
              )
        }
     }
 }

【问题讨论】:

    标签: ios image swiftui lazyvgrid


    【解决方案1】:

    看起来图像具有不同的纵横比,因此如果它们缩放到相同的宽度,则高度是不同的。 如果您希望以相同的纵横比裁剪所有图像,则可以遵循以下方法: Clip image to square in SwiftUI

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-02
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多