I have a foreach with five options to link different View how to do it with button or NavigationLink using switch Case.
HStack()
{
ForEach(MockData.items)
{ item in
ZStack
{
Button(action: {}) {
NavigationLink("") {
switch item {
case "MedicalView":
MedicalView()
case "IllnesView":
IllnessView()
case "VaccuneView":
VaccuneView()
case "DeworView":
DeworView()
case "AllergieView":
AllergieView()
}
}
}
{
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(item.color.self)
.frame(width: 70, height: 70)
.disabled(false)
}
Image(systemName: item.image)
.foregroundColor(.white)
.font(.system(size: 30))
}
}//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 {
let id = UUID()
let color: Color
let image: String
}
struct MockData {
static var items = [Item(color: .red, image: "heart"),
Item(color: .blue, image:"pill"),
Item(color: .orange, image: "syringe"),
Item(color: .green, image: "microbe"),
Item(color:.purple, image: "allergens")]
}