Skip to content

An alternative SwiftUI Grid view for older platforms.

License

Notifications You must be signed in to change notification settings

LiYanan2004/AdaptiveGrid

Repository files navigation

Adaptive Grid

An alternative Grid View for old platforms.

If your minimum deployment target is lower than iOS 16, macOS 11, watchOS 9 or tvOS 16, you may need to use AdaptiveGrid as to support older platforms.

Otherwise, go ahead and use SwiftUI’s built in Grid.

Platforms

  • iOS 14.0+
  • macOS 11.0+
  • tvOS 14.0+
  • watchOS 7.0+

Getting Started

It’s similar to SwiftUI’s native Grid, so you can quickly gettting started.

AdaptiveGrid {
    GridRowContainer {
        GridCellContainer {
            Text("Hello")
        }
        GridCellContainer {
            Image(systemName: "globe")
        }
    }
    
    GridRowContainer {
        GridCellContainer {
            Image(systemName: "hand.wave")
        }
        GridCellContainer {
            Text("World")
        }
    }
}

You can specify both horizontal and vertical spacing just like how you use the SwiftUI’s native Grid view.

AdaptiveGrid(horizontalSpacing: 10, verticalSpacing: 10) {
    ...
}

If you want to add dividers as row seperators, specify showDivider to true.

AdaptiveGrid(showDivider: true) {
    ...
}

Note

Currently, Adaptive Grid takes the maximum space horizontally, which is the same with SwiftUI’s built-in Grid with Dividers added, so you may need to specify a width or maxWidth manually to control the size.

About

An alternative SwiftUI Grid view for older platforms.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages