Skip to content

Instantly share code, notes, and snippets.

@pdarcey
Created August 30, 2021 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdarcey/81e8961c23c91042321a911f35aab29b to your computer and use it in GitHub Desktop.
Save pdarcey/81e8961c23c91042321a911f35aab29b to your computer and use it in GitHub Desktop.
Getting SwiftUI Grids to adapt to multiple screen sizes/orientations

Usually, you set your grid up with something to generate your [GridItems], often something like:

var items: [GridItem] {
    return Array(repeating: .init(.adaptive(minimum: 250), spacing: 10, alignment: .center), count: 1)
}

See that 1 at the end? That's the important bit!

(Technically, it can be other numbers too and still work, but 1 is kinda what the Grid will be looking for, and what you expect the result to look like, when it adaptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment