-
-
Save sturdysturge/c32764357e777baed0499703d47c0ef8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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