1

I have the following code:

let gridItems = [GridItem(.adaptive(minimum: 300, maximum: 400), spacing: 10)]

ScrollView(.vertical, showsIndicators: false) {
    LazyVGrid(columns: gridItems) {
        ForEach(item) { i in
            HStack(spacing: 0) {
                Text("Testing")
                Spacer()
            }
            .border(.pink)
        }
    }
    .background(.green)
    .border(.blue)
}
.border(.red)

it draws this:

enter image description here

How can I remove the leading and trailing gap? Where is that coming from?

zumzum
  • 17,984
  • 26
  • 111
  • 172
  • Does this answer your question https://stackoverflow.com/a/63027052/12299030? – Asperi Jun 13 '22 at 18:42
  • no. I did not try to set both spacings to 0 at the same time, but, I just tried and I still have that padding going on. – zumzum Jun 13 '22 at 18:45

1 Answers1

2

Adaptive item introduce width limitation:

let gridItems = [GridItem(.adaptive(minimum: 300, maximum: 400), spacing: 10)]
                                                  ^^^^^^^^^^^^ << here !!

in general internal grid spacing is configured as described in https://stackoverflow.com/a/63027052/12299030

Asperi
  • 228,894
  • 20
  • 464
  • 690