How to create two column list in swiftUI using List view?

1.9k views Asked by At

I am new to SwiftUI. I need to create a list that is displaying in two columns. Its more likely a collectionView with two items per row. The condition is I need to create it using "List" because I need to add a "drag and drop to reorder" functionality on this list.

So far I have implemented it using HStack and VStack but in this case there is no option to drag and reorder the list.

Here is the code I have done so far:

           ZStack{
              Button(action: {
                 }) {
                      HStack{
                         Image(systemName: "person.crop.circle.fill")
                         Text(font)
                             .font(.system(size: 13 ))
                         .foregroundColor(.black)
                            .frame(minWidth: UIScreen.main.bounds.size.width/4, maxWidth: UIScreen.main.bounds.size.width/4)
                         .padding(.horizontal)
                       }
                       .padding(10)
                     }
                     .foregroundColor(Color.black)
                     .background(Color.white)
                     .cornerRadius(8)
                     .background(
                     RoundedRectangle(cornerRadius: 5)
                         .fill(Color.white)
                         .shadow(color: .gray, radius: 2, x: 0, y: 2)
                     )
          }

My question is: how can I create collection view type of two column list in SwiftUI Using List?? IF my implementation using HStack and Stack sounds good then: Is there any way to implement drag and drop to reorder list functionality on it??

Using LazyVGrid is not possible for me because my requirement is ios13.

Any help will be appreciated.

Thanks!!

Update: I solved it using UICollectionView wrapped in UIViewRepresentable in swiftui.

0

There are 0 answers