AdaptiveGrid

main

An alternative SwiftUI Grid view for older platforms.
LiYanan2004/AdaptiveGrid

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.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 12:01:03 GMT-0900 (Hawaii-Aleutian Daylight Time)