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

问题描述 投票:0回答:3

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

我只放文字供参考。我参考了一些链接,但它对我没有帮助。还尝试了其他与填充相关的修饰符,但对我也没有帮助。

  • 代码

    .......   
    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)
       }
    .....
    

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

list swiftui
3个回答
2
投票

列表在右侧和左侧放置了额外的空格,因此您可以使用

padding()
修饰符来解决问题。

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)

0
投票

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

.padding(-10.0)

对你的身体。


0
投票

您似乎在 SwiftUI 中的列表单元格的左侧和右侧遇到了额外的空间。要调整此间距,您可以使用

listRowInsets
修饰符。通过应用
listRowInsets
,您可以精确控制列表中每行的插入。

使用方法如下:

.listRowInsets(.init(top: 10, leading: 0, bottom: 10, trailing: 10))

在此示例中,

top
bottom
值设置为
10
,调整垂直填充,而
leading
trailing
值分别设置为
0
10
,控制垂直填充左右填充。

您可以根据您的具体布局要求随意调整这些值。这应该可以帮助您消除列表单元格两侧的额外空间。

© www.soinside.com 2019 - 2024. All rights reserved.