【发布时间】:2023-01-09 19:56:24
【问题描述】:
我想像这样显示类似于 UICollectionView 的图像网格
每种颜色代表一个图像。
当我执行以下操作时
struct ContentView: View {
var body: some View {
ScrollView{
ForEach(0..<8) { i in
HStack {
ForEach(0..<3) { j in
ZStack(alignment: .center) {
Image("image")
.background(Color.random)
.clipped()
.aspectRatio(contentMode: .fill)
}
.frame(width: 120, height: 120)
.background(Color.random)
}
}
}
}
}
}
我得到一张不受其框架约束的图像,因此填满了整个屏幕。
【问题讨论】: