tyirvine
tyirvine

Reputation: 2341

Is it possible to shrink the space surrounding a SwiftUI grid?

I noticed when building a small LazyHGrid (5 * 5 of squares) the total width of the grid was flush to the squares. However, the vertical was completely unbounded. I don't want it to fill the entire vertical bound so I tried a bunch of different ways such as .scaleToFit and others but nothing worked to shrink fit the grid to the squares.

I'm guessing maybe this just isn't made to be because grids in SwiftUI weren't intended for such a purpose but it seems odd. I know that the grids can be bounded by using a .frame() but that feels like a band-aid solution to me.

Is it possible to bound a grid's outer spacing?

Upvotes: 4

Views: 416

Answers (1)

Asperi
Asperi

Reputation: 257711

I assume you just need fixed size, like below (tested with Xcode 12.0 / iOS 14)

LazyHGrid(rows: [GridItem(.flexible(minimum: 200, maximum: 200))]) {

  // content here

}.fixedSize()    // << here !!

Upvotes: 2

Related Questions