【问题标题】:Extra Space in List (left and right side) SwiftUI列表中的额外空间(左侧和右侧)SwiftUI
【发布时间】:2020-02-12 05:28:44
【问题描述】:

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

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

  • 代码

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


    【解决方案1】:

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

    .padding(-10.0)
    

    到你的身体。

    【讨论】:

      【解决方案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)
      

      【讨论】:

        猜你喜欢
        • 2020-10-20
        • 1970-01-01
        • 2012-12-23
        • 2015-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-21
        相关资源
        最近更新 更多