Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 15, 2021 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/c32764357e777baed0499703d47c0ef8 to your computer and use it in GitHub Desktop.
Save sturdysturge/c32764357e777baed0499703d47c0ef8 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var value1 = Double()
@State var value2 = Double()
@State var total = Double()
func addValues() {
total = value1 + value2
}
var body: some View {
VStack {
Slider(value: $value1, in: 0...100,
minimumValueLabel: Text("0"),
maximumValueLabel: Text("100")) {
Text("Value 1")
}
.onChange(of: value1) {
_ in addValues()
}
Slider(value: $value2, in: 0...100,
minimumValueLabel: Text("0"),
maximumValueLabel: Text("100")) {
Text("Value 2")
}
.onChange(of: value2) {
_ in addValues()
}
Text("Total: \(total)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment