SwiftUI - 删除单元格之间的 space
SwiftUI - Remove space between cells
我正在 SwiftUI 中实现列表视图。我试图接近的是让任何其他单元格或父视图之间没有 space 的单元格。
所以在这个屏幕截图中,您可以看到每个单元格之间有一个 space,还有 space 和 phone 的边缘,我想删除它。
struct FlickrView : View {
var flickrResponse: [FlickrResponse]
var body: some View {
List(flickrResponse) { item in
FlickrImageCell(response: item)
}
}
}
struct FlickrImageCell : View {
var response: FlickrResponse
var body: some View {
return ZStack(alignment: .topLeading) {
Image(uiImage: response.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: nil, height: 100.0, alignment: .center)
.clipShape(Rectangle())
.padding(0)
Text(response.title).fontWeight(.medium).multilineTextAlignment(.center)
}
}
}
我试过这个修饰符:
.padding(EdgeInsets(top: 0, leading: -20, bottom: 20, trailing: -20))
但是我使用这种方法有两个问题:首先,我认为写字面量的负值不方便。其次,底部填充不适用于任何值。
有什么建议吗?
我对 listRowInsets 很满意
struct ContentView: View {
var body: some View {
List {
Color.red
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.blue
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.yellow
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
我正在 SwiftUI 中实现列表视图。我试图接近的是让任何其他单元格或父视图之间没有 space 的单元格。
所以在这个屏幕截图中,您可以看到每个单元格之间有一个 space,还有 space 和 phone 的边缘,我想删除它。
struct FlickrView : View {
var flickrResponse: [FlickrResponse]
var body: some View {
List(flickrResponse) { item in
FlickrImageCell(response: item)
}
}
}
struct FlickrImageCell : View {
var response: FlickrResponse
var body: some View {
return ZStack(alignment: .topLeading) {
Image(uiImage: response.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: nil, height: 100.0, alignment: .center)
.clipShape(Rectangle())
.padding(0)
Text(response.title).fontWeight(.medium).multilineTextAlignment(.center)
}
}
}
我试过这个修饰符:
.padding(EdgeInsets(top: 0, leading: -20, bottom: 20, trailing: -20))
但是我使用这种方法有两个问题:首先,我认为写字面量的负值不方便。其次,底部填充不适用于任何值。
有什么建议吗?
我对 listRowInsets 很满意
struct ContentView: View {
var body: some View {
List {
Color.red
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.blue
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
Color.yellow
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}