struct ContentView: View { var body: some View { VStack { Grid { GridRow { Label("DevTechie", systemImage: "heart") Label("iOS Development", systemImage: "graduationcap") } } .font(.title3) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { Label("DevTechie", systemImage: "heart") Label("iOS Development", systemImage: "graduationcap") } GridRow { Label("SwiftUI", systemImage: "swift") Label("UIKit", systemImage: "gear") } } .font(.title3) } .padding() } }
struct GridCell: View { let systemName: String let title: String var body: some View { HStack { Image(systemName: systemName) Text(title) } } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") GridCell(systemName: "graduationcap", title: "iOS Development") } GridRow { GridCell(systemName: "swift", title: "SwiftUI") GridCell(systemName: "gear", title: "UIKit") } } .font(.title3) } .padding() } }
Note: Grid and GridRows behave like a collection of HStack and VStack combined together, but Gridhandles row and column creation as a single operation which makes it efficient. While Grid is creating these rows and columns, it applies alignment and spacing to the cells.
.gridCellColumns(2)
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) } .gridCellColumns(2) GridRow { GridCell(systemName: "swift", title: "SwiftUI") GridCell(systemName: "gear", title: "UIKit") } } .font(.title3) } .padding() } }struct GridCell: View { let systemName: String let title: String var body: some View { HStack { Image(systemName: systemName) Text(title) } } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .frame(maxWidth: .infinity) .background(.orange.gradient) } .gridCellColumns(2) GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .frame(maxWidth: .infinity) .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .frame(maxWidth: .infinity) .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid(alignment: .leading){ GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .background(.orange.gradient) } .gridCellColumns(2) GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid(alignment: .leading, horizontalSpacing: 0, verticalSpacing: 0){ GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .background(.orange.gradient) } .gridCellColumns(2) GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .background(.orange.gradient) } .gridCellColumns(2) Color.blue GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
Color.blue.gridCellUnsizedAxes([.horizontal, .vertical])
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .background(.orange.gradient) } .gridCellColumns(2) Color.blue .gridCellUnsizedAxes([.horizontal, .vertical]) GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .font(.largeTitle) .padding() .background(.orange.gradient) } .gridCellColumns(2) Color.blue .frame(minHeight: 2) .gridCellUnsizedAxes([.horizontal, .vertical]) GridRow { GridCell(systemName: "swift", title: "SwiftUI") .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
struct ContentView: View { var body: some View { VStack { Grid { GridRow { GridCell(systemName: "heart", title: "DevTechie") .frame(maxWidth: .infinity) .padding() .background(.orange.gradient) } GridRow { GridCell(systemName: "swift", title: "SwiftUI") .frame(maxWidth: .infinity) .padding() .background(.teal.gradient) GridCell(systemName: "gear", title: "UIKit") .frame(maxWidth: .infinity) .padding() .background(.indigo.gradient) } } .font(.title3) .foregroundColor(.white) } .padding() } }
With that we have reached the end of this article. Thank you once again for reading. Subscribe our newsletter at https://www.devtechie.com