Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Building a Tinder-like swipe feature on SwiftUI

I am trying to build a tinder-like swipe feature but I have an issue. All the cards get stacked together on the first screen like in the screenshot below:

enter image description here

It is supposed to look like below

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Here is my code:

  MainView

  NavigationView  {
                VStack () {
       
                        ZStack {
                            ForEach(outingsVM.outings, id: \.dateId) { outing in
                                 CardView(outing: outing)
                             }
                         }
                    
                }
               
            }

CardView

 ZStack {
            VStack {
     
     
                HStack {
                        Text("\(outing.name), \(outing.age)")
                }
                .frame(width: 320, alignment: .leading)
                   
                HStack (alignment: .center) {
                    Image(systemName: "figure.walk.circle")
                    Text("\(outing.place)")
                }
                .frame(width: 320, alignment: .leading)
                
                HStack {
                    Image(systemName: "calendar.circle")
                    Text("\(outing.date)  \(outing.time)")
                }
                .frame(width: 320, alignment: .leading)
                
                HStack {
                    Image(systemName: "creditcard.circle")
                    Text("\(outing.payment)")
                }
                .frame(width: 320, alignment: .leading)
          
               // }
                HStack (){
                    Spacer()
                    //accept date
                    Button {
                        showingModal = true
                    } label: {
                        Image(systemName: "checkmark.circle.fill")
                            .font(.system(size: 50))
                            .foregroundColor(.green)
                    }
                    
                    Spacer()
                    
                    //reject date
                    Button {
                        swipeCard(width: -200)
                    } label: {
                        Image(systemName: "xmark.circle.fill")
                            .font(.system(size: 50))
                            .foregroundColor(.red)
                    }
                    
                    Spacer()
                }
                .frame(width: 320)
                .padding()
           }
        }

 

How can I fix this?

>Solution :

You need to add a background to your CardView, e.g.

struct CardView: View {

    var body: some View {
        VStack {
            

        }
        .padding()
        .background(RoundedRectangle(cornerRadius: 8).fill(.white))        
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading