swift 如何让列表从顶部开始且没有填充
swift how can I make list start at the top with no padding
我是 swiftui 的新手,使用的是版本 2。我有一个从数据库中填充的列表。我正在努力解决的问题是让我的 List 从最顶部开始并消除 padding 。如果您查看下图,您会在顶部数据“Places My circle”和列表之间看到灰色 space。任何有关消除灰色 space 的帮助都会很棒。这是我的代码
struct MainView: View {
@State var model: [MainModel] = []
var body: some View {
VStack {
HStack {
Text("Places")
Text("My Circle | Location")
}
TimeLineView(model: $model) // List comes from here
}
}
}
struct TimeLineView: View {
@Binding var model: [MainModel]
var body: some View {
List {
ForEach(model) { value in
// Simple elements populated
}
}.listStyle(GroupedListStyle())
.padding(0)
}
}
那个padding是List的分组样式,如果要去掉就用PlainListStyle
List {
ForEach(model) { value in
// Simple elements populated
}
}.listStyle(PlainListStyle()) // << here !!
我是 swiftui 的新手,使用的是版本 2。我有一个从数据库中填充的列表。我正在努力解决的问题是让我的 List 从最顶部开始并消除 padding 。如果您查看下图,您会在顶部数据“Places My circle”和列表之间看到灰色 space。任何有关消除灰色 space 的帮助都会很棒。这是我的代码
struct MainView: View {
@State var model: [MainModel] = []
var body: some View {
VStack {
HStack {
Text("Places")
Text("My Circle | Location")
}
TimeLineView(model: $model) // List comes from here
}
}
}
struct TimeLineView: View {
@Binding var model: [MainModel]
var body: some View {
List {
ForEach(model) { value in
// Simple elements populated
}
}.listStyle(GroupedListStyle())
.padding(0)
}
}
那个padding是List的分组样式,如果要去掉就用PlainListStyle
List {
ForEach(model) { value in
// Simple elements populated
}
}.listStyle(PlainListStyle()) // << here !!