0

I am using iOS 14 and Xcode 12 to learn SwiftUI.

I want to use Button to add new or more VStacks\.

Anyone know how to use the buttons and add a new VStack?

Any help would be appreciate. This is my code.

Button(action: {
   VStack{
         Text("hello")
   }
}, label: {
      Image(systemName: "plus.circle.fill")
           .foregroundColor(.black)
})
SimpsonHuang
  • 43
  • 1
  • 6

1 Answers1

1

not a brilliant idea, but if that's what you want to do, try this:

struct ContentView: View {
    @State private var vstacks = 0
    
    var body: some View {
            Button(action: { vstacks += 1 } ) {
                Image(systemName: "plus.circle.fill").foregroundColor(.black)
            }
            ForEach(0..<vstacks, id: \.self) { vs in
                VStack{
                    Text("hello vstack: \(vs) here")
                }
            }
    }
}