我是 SwiftUI 新手
我正在尝试创建这样的部分,其中每一行都与另一行分开。有点像背景彼此不连接的部分。看看图片:(图片来自 dribbble)
但我的结果是这样的:
(我创建了蓝色背景,以便大家可以清楚地看到行)
这是我的代码:
import SwiftUI
struct ProductPageView: View {
init() {
UITableView.appearance().backgroundColor = .clear // Uses UIColor
}
var body: some View {
NavigationView {
ZStack {
Color.blue.edgesIgnoringSafeArea(.all)
VStack {
List {
ForEach(arrayProduct, id: \.name) { dataProduct in
ProductListCell(item: dataProduct)
}
.listRowInsets(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
}
.listStyle(InsetGroupedListStyle())
}
}
.navigationTitle("Produk")
}
}
}
我用过listRowInsets
但这只是拉伸它。
如何创建行之间的分隔?
任何帮助将不胜感激。
谢谢
我没有尝试像素完美的再现,因为我没有资源,但以下概述了实现此目的的一种方法。
代码中的注释解释了一些关键部分:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ZStack {
Color.blue.edgesIgnoringSafeArea(.all)
VStack {
// This handles the display of the
// section header
HStack {
// The text & spacer are grouped
// so that you can pad accordingly
Text("Stuff")
Spacer()
}
.padding(.bottom, 2)
.padding(.leading, 10)
// A VStack contains your list of items
VStack {
ForEach(0...3, id: \.self) { element in
// Each grouping (a product for you)
// will exist within this top level
// HStack
HStack {
// A new HStack (or another view of
// your choice) will contain the views
// that compose your product entry
HStack {
Text("\(element)")
Spacer()
}
.padding() // Provides some buffer around the product
.background(Color.white)
.contentShape(Rectangle()) // For tapping
.cornerRadius(5.0)// Rounding!
}
// Custom padding can tailor your spacing needs
.padding([.top, .bottom], 2)
.padding([.trailing, .leading], 10)
}
}
Spacer()
}
}
.navigationTitle("Produk")
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)