I want to use Foreach and NavigationLink with SfSymbol for menu

I want to use Foreach and NavigationLink with SfSymbol for menu where each rectangle comes out SFSymbol differently and be able to link to the different View.

HStack()

                    {
                        ForEach(MockData.items)
                        {item in
                            
                            //NavigationLink(
                            
                            RoundedRectangle(cornerRadius: 10 )
                                .frame(width: 70, height: 70)
                                .foregroundStyle(item.color.gradient)
                            
                            
                            
                        }
                        
                        
                        
                        
                        
                    }//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")]
    }
        

I need help figuring out how to do it.

Accepted Reply

ZStack
{
	RoundedRectangle(cornerRadius: 10 )
		.frame(width: 70, height: 70)
		.foregroundStyle(item.color.gradient)

	Image(systemName: item.image)
}

Have you tried that?

  • Hello: But how do I make the links to the views.

Add a Comment

Replies

ZStack
{
	RoundedRectangle(cornerRadius: 10 )
		.frame(width: 70, height: 70)
		.foregroundStyle(item.color.gradient)

	Image(systemName: item.image)
}

Have you tried that?

  • Hello: But how do I make the links to the views.

Add a Comment