Below is an example to populate a view with rectangular shapes navigation link items in the grid with SwiftUI:
import SwiftUI
struct TestNavigationStackView: View {
var grid: [GridItem] = Array(repeating: .init(.flexible()), count: 6)
let colors: [Color] = [ .yellow, .cyan, .orange, .gray, .indigo, .brown, .red, .green, .blue, .mint, .primary, .purple]
var body: some View {
NavigationStack {
LazyVGrid(columns: grid) {
ForEach(colors, id: \.self) { color in
NavigationLink {
// YourViewForLink()
} label: {
Rectangle()
.fill(color)
.frame(width: 200, height: 300)
}
.padding(20)
.buttonStyle(.card)
}
}
}
}
}
struct TestRectangularShapeNavigationItemsView_Previews: PreviewProvider {
static var previews: some View {
TestRectangularShapeNavigationItemsView()
}
}
Output: