user1591668
user1591668

Reputation: 2893

swift how can I make list start at the top with no padding

I am new to swiftui and using version 2 . I have a List which populates from the database . The issue I am struggling with is getting my List to start at the very top and eliminate padding . If you look at the image below you see a gray space between the top data "Places My circle" and the list . Any help on eliminating that gray space would be great . This is my code

struct MainView: View {
    @State var model: [MainModel] = []
    var body: some View {
      
        VStack {
            HStack {
            Text("Places")
            Text("My Circle | Location")
            }
            TimeLineView(model: $model) // List comes from here
        }

    }
    
}

struct TimeLineView: View {
    @Binding var model: [MainModel]

    var body: some View {
        
        List {
            ForEach(model) { value in
                
                // Simple elements populated
            }
        }.listStyle(GroupedListStyle())
        .padding(0)
  
    }
}

enter image description here

Upvotes: 2

Views: 764

Answers (1)

Asperi
Asperi

Reputation: 258441

That padding is a List's grouped style, if you want to remove it then use PlainListStyle

    List {
        ForEach(model) { value in
            
            // Simple elements populated
        }
    }.listStyle(PlainListStyle())     // << here !!

Upvotes: 5

Related Questions