I have an array of images that I am passing through a LazyVgrid.
I am wondering how I assign a NavigationLink to the Image names stored within the array, clicking icon1 navigates to page1, ect for all 8.
------ Swift UI -------
import SwiftUI
struct Grid: View {
var images: [String] = ["icon1", "icon2", "icon3", "icon4",
"icon5", "icon6", "icon7","icon8"]
var columnGrid: [GridItem] = [GridItem(.flexible(), spacing: 25), GridItem(.flexible(), spacing: 25)]
var body: some View {
LazyVGrid(columns: columnGrid, spacing: 50) {
ForEach(images, id:\.self) { image in
Image(image)
.resizable()
.scaledToFill()
.frame(width: (UIScreen.main.bounds.width / 2.75 ) - 1,
height: (UIScreen.main.bounds.width / 2.75 ) - 1)
.clipped()
.cornerRadius(25)
}
}
}
}
For occasions like this I would prefer an enum that holds all related information. You also could do this with a struct the reasoning behind this stays the same.
And your
Grid
View:Result: