【发布时间】:2021-11-02 20:32:58
【问题描述】:
我必须做一个带有图像、两个文本和两个按钮的 collectionView。我想在 LazyVGrid 中增加 VStack 的填充,但无法实现。你能帮我找出问题所在吗?
let columns = Array(repeating: GridItem(.flexible(), spacing: 20, alignment: .center), count: 2)
var body: some View {
NavigationView {
ScrollView {
LazyVGrid(columns: columns, spacing: 20, content: {
ForEach(data, id:\.self) { item in
VStack(alignment: .leading, spacing: 10) {
Image("\(item.image)")
.resizable()
.frame(width: 150, height: 200)
.padding(4)
.cornerRadius(10)
Text(item.name)
Text(item.price)
HStack(spacing: 15) {
Button(action: {}) {
HStack {
Image(systemName: "cart")
Text("В Корзину")
.fixedSize(horizontal: true, vertical: false)
}
.padding(10)
.background(Color.blue)
.foregroundColor(Color.white)
.cornerRadius(10)
}
Button(action: {}) {
Image(systemName: "heart")
}
.padding(10)
.background(Color.white)
.clipShape(Rectangle())
.foregroundColor(.blue)
.cornerRadius(10)
}
} .foregroundColor(Color.black)
.background(Color.red)
.cornerRadius(25)
.padding(15)
}
}).padding(15)
}
}
}
}
【问题讨论】: