列表中的额外空间(左侧和右侧)SwiftUI

时间:2019-10-15 13:48:10

标签: list swiftui

我正在尝试创建列表屏幕,但是在创建单元格时,它会在左右两侧留出额外的空间。

我只提供文字作为参考。我引用了一些链接,但对我没有帮助。并尝试了其他与填充相关的修饰符,但对我也无济于事。

  • 代码

    .......   
    let text = "Hello stack work is going very fine. let's check the code is woking or not properly"
        var body: some View {
           List {
                Text(text).background(Color.blue)
                Text(text).background(Color.blue)
           }.foregroundColor(.white)
       }
    .....
    

图像我附加了箭头指示的空间

2 个答案:

答案 0 :(得分:1)

列表在左右两侧增加了一个空格,因此您可以使用VStack(alignment: .leading) { List { Text("Hello stack work is going very fine. let's check the code is woking or not properly") .background(Color.blue) Text("Hello stack work is going very fine. let's check the code is woking or not properly") .background(Color.blue) } .foregroundColor(.white) } .padding(.leading, -16) // you can use as per your requirement(-16) .padding(.trailing, -20) 修饰符来解决问题。

{{1}}

答案 1 :(得分:0)

List在两侧都添加了一些填充,就像UITableView一样。通常,它有助于提高可读性,但是如果您坚持要删除它,则可以添加

.padding(-10.0)

到你的身体。