Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swiftui

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.

like image 247
kangarooChris Avatar asked Feb 01 '26 11:02

kangarooChris


1 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())
like image 83
Asperi Avatar answered Feb 04 '26 00:02

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!