Created
June 20, 2020 19:57
-
-
Save PetreVane/51e41184a5bb2bf9e0cd6a0d13f97519 to your computer and use it in GitHub Desktop.
How to initialize a Stepper in SwiftUI
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 private var orderCount = 0 | |
var body: some View { | |
VStack { | |
// Initializing a Stepper | |
Stepper(onIncrement: { self.orderCount += 1 }, | |
onDecrement: { self.orderCount -= 1 }) | |
{ Text("Value changed. Order count is now \(orderCount) ") } | |
// You can also initialize a new Stepper this way (easier) | |
Stepper("Set the order amount", value: $orderCount) | |
Text("Your order count is now \(orderCount)") | |
// Adding a slider is also very easy | |
Slider(value: $temperature, in: (0 ... 10)) | |
.rotationEffect(Angle(degrees: temperature)) | |
// Rotation effect will rotate the slider, as you change the values. | |
// See different types of init | |
Text("Temperature is now \(temperature)") | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment