List View in SwiftUI is showing a grey area above the list which I can't get rid of

Viewed 402

I am not gonna lie, but the modifiers in SwiftUI are super tricky. I want to get rid of the grey area above my list. I have tried all, padding, offset, frame, you name it. It's still there. Why is it there anyway. Is it some kind a header that I could possibly undefine? Anyway, here is the code:

           List{
                
                ForEach(prim, id: \.id)  { value in
                    GeometryReader { geometry in
                    HStack {
                        Text(value.label)
                            .font(.system(size: 12))
                            .padding(.vertical, 0)
                            .frame(width: geometry.size.width/4)
                        
                        Spacer(minLength: geometry.size.width/4)
                        
                        TextField("", value: value.data   , formatter: NumberFormatter())
                            .font(.system(size: 12))
                            .padding(.vertical, 0)
                            .keyboardType(.numberPad)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            
                    }.padding(.top, 0)
                    }.padding(.top, 0)
                }.padding(.top, 0)
            }
            .padding(.top, 0)
            .listStyle(GroupedListStyle())

enter image description here I have not defined the grey area, so why is it there? It pushes my list down and so my third item in the list disappears.

2 Answers

If it is not empty NavigationView (because it is not clear where is this List placed), then it is due to used list style.

You can use instead plain style

        }
        .padding(.top, 0)
        .listStyle(PlainListStyle())

Before var body: some View put this:

init()
{
    UITableView.appearance().backgroundColor = .clear
}
Related