我正在 SwiftUI 中实现列表视图。我试图实现的方法是让单元格在任何其他单元格或父视图之间没有空间。
因此,在这张屏幕截图中,您可以看到每个单元格之间都有一个空格,并且与手机边缘之间也有一个空格,我想将其删除。
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))
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)