Connect with us

Code

GridView – Easy Grids with SwiftUI

Lay out your data in the blink of an eye. Keep your code clean.

GridView is a free, and open-source library for SwiftUI that makes creating grids easier and much cleaner.

  • Improves code quality. Create a grid using GridView constructor – simply pass your data and we’ll deal with the rest. Simple as never!
  • Designed for SwiftUI. While developing the library, we have used the power of SwiftUI to give you powerful tool to speed up your implementation process.

GridView Usage

1. Call initialiser

To declare a Grid for your data set, call the constructor:

struct ContentView: View {
    private let data = [SomeData]()

    var body: some View {
        GridView(data, id: \.self) { element in
            SomeItem(element: element)
        }
    }
}

2. Customise Grid

Your GridView can be customised by calling configBuilder inside the initialiser:

struct ContentView: View {
    private let data = [SomeData]()

    var body: some View {
        GridView(data, id: \.self, content: SomeItem.init, configBuilder: { $0
            .insertionPolicy(.fill)
            .columns(4)
            .verticalSpacing(12)
        })
    }
}

3. Declare number of columns

You can change the number of columns of an item by calling .columns of Item:

struct ContentView: View { ... }
struct SomeItem: View {
    ...

    var body: some View {
        ...
            .columns(2)
    }
}

 

Try our demo

See for yourself how does it work by cloning project we created.

GridView on GitHub: https://github.com/Mijick/GridView
Platform: iOS
⭐️: 9
Advertisement

Trending