I'm having trouble with the code to link the buttons to the following View.
ZStack(){
Color(.systemGray6).ignoresSafeArea()
VStack()
{
ScrollView(.horizontal, showsIndicators: false)
{
HStack()
{
ForEach(MockData.items)
{ item in
ZStack
{
Button(action:{ })
{
NavigationLink(destination: selectedView(name: item.name))
{ EmptyView()}
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(item.color.self)
.frame(width: 70, height: 70)
}
Image(systemName: item.image)
.foregroundColor(.white)
.font(.system(size: 30))
.padding(25)
}
}
}//scrollview
//opciones
}//cierre del VStack
.padding(.top, 20)
.padding(.leading)
Spacer()
}//cierre Zstack
} //cierre de Zstack
.navigationTitle("Caracteristicas")
.toolbar{
ToolbarItem(placement: .navigationBarLeading)
{
Button(action:{},
label: {
Image(systemName: "switch.2")})
}
ToolbarItem(placement: .navigationBarTrailing)
{
Button(action:{},
label: {Image(systemName: "person.circle")})
}
}//toolBar
.accentColor(.red)
}
}
}
struct Item: Identifiable {
var id = UUID()
var name: String
var color: Color
var image: String
}
struct MockData {
static var items = [Item(name: "Medical" ,color: .red, image:"heart"),
Item(name: "Illnes" ,color: .blue, image:"pill"),
Item( name:"Vaccune" ,color: .orange, image: "syringe"),
Item(name: "Dewor" ,color: .green, image: "microbe"),
Item(name: "Allergie" ,color:.purple, image: "allergens")]
}
@ViewBuilder
private func selectedView (name: String) -> some View {
switch name {
case "Medical": MedicalView()
case "Illness": IllnessView()
case "Vaccune": VaccuneView()
case "Dewor": DeworView()
case "Allergie": AllergieView()
default: EmptyView()
}
}