I have checked several questions here about the grid view but my question is a bit different , i want to create a grid view for buttons so each button when pressed navigate to different view, So it has look like this image: This is the grid buttons view
so i have wrote this code here but looks like i wasn't very successful to get what i want, Is there a better idea to achieve this design as grid view ?
import SwiftUI
struct MainCollectionView: View {
var MainCollectionView: CollectionView
@State private var isActive : Bool = false
var body: some View {
NavigationView{
ScrollView {
ForEach(0..<2) { row in
HStack {
ForEach(0..<2) { col in
Button(MainCollectionView.title) {
self.isActive = true
}//button exit
.accentColor(Color.black)
.padding(.horizontal,16)
.padding(.vertical, 10)
.background(
Capsule().strokeBorder(Color.white, lineWidth: 1.25))
}
}
}
}}
}
}
struct MainCollectionView_Previews: PreviewProvider {
static var previews: some View {
MainCollectionView(MainCollectionView: CollectionViewData[0])
}
}