Reputation: 53
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)
})
Upvotes: 0
Views: 1083
Reputation: 36627
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")
}
}
}
}
Upvotes: 1