Is there any way to reset the scrollview or total app view including foreach loop with a reset button. I have following code which draws rectangles. Add amount and rotate. I want to reset all with a button click. Please help. This is a playground project.
import SwiftUI
struct ContentView: View {
let columns = [
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())
]
@State private var Amout = 10
@State private var angle = 0.0
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 15) {
ForEach(0..<20) { number in
Rectangle()
.foregroundColor(Color.red)
.frame(width: 50, height: 80)
.cornerRadius(10)
.shadow(color: .black, radius: 5, x: 2, y: 2)
.rotationEffect(.degrees(angle))
.overlay(
Text("\(number)").foregroundColor(.white)
)
.onTapGesture {
Amout += number
angle += 5
}
}
}.padding(.all, 10)
Text ("Total Amount is : \(Amout)")
.font(.system(size: 20))
.bold()
.padding()
Button {
// Help needed here :-)
} label: {
Text("Reset")
.font(.system(size: 16))
.bold()
.foregroundColor(Color.blue)
}
}
}
}