Post

Replies

Boosts

Views

Activity

It doesn't work with the code to bind the buttons to the following Views.
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() } }
1
0
289
Apr ’24
How can I link to multiple views using Foreach. When I have five options with icons. Each option goes to a different link View
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")] }
2
0
433
Mar ’24
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.
1
0
307
Mar ’24
Using Foreach
I'm using foreach to make some options in a horizontal scrollview then I want to link the next page view. The problem is putting Symbol SF in the code. How can I put this according to the code? ScrollView(.horizontal, showsIndicators: false) { HStack() { ForEach(MockData.items) {item in RoundedRectangle(cornerRadius: 10 ) .frame(width: 80, height: 80) .foregroundStyle(item.color.gradient) } } struct Item: Identifiable { let id = UUID() let color: Color //var image: Image } struct MockData { static var items = [Item(color: .red), Item(color: .blue), Item(color: .orange), Item(color: .green), Item(color:.purple)] }
0
0
226
Jan ’24
As I can include several buttons that swipe from right to left at the top of the screen
As I can include several buttons that swipe from right to left at the top of the screen. Having this code. @Binding var selected: Int var body: some View { NavigationView{ VStack(){ } .navigationTitle("Carecteries") .toolbar{ ToolbarItem(placement: .navigationBarLeading ) { Button(action:{ }, label: {Image(systemName: "person.circle")}) } ToolbarItem(placement: .navigationBarTrailing) { Button(action:{ }, label: {Image(systemName: "i.circle")}) } } .accentColor(.red) }//close Navigation } } struct HomeView_Previews: PreviewProvider { static var previews: some View { HomeView(selected: .constant(0)) } }
0
0
250
Dec ’23