init(_:value:step:onEditingChanged:)
Creates a stepper with a title key and configured to increment and decrement a binding to a value and step amount you provide.
Declaration
@export(implementation) nonisolated init<V>(_ titleResource: LocalizedStringResource, value: Binding<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V : StrideableParameters
- titleResource:
Text resource for the stepper’s localized title describing the purpose of the stepper.
- value:
A Binding to a value that you provide.
- step:
The amount to increment or decrement
valueeach time the user clicks or taps the stepper’s plus or minus button, respectively. Defaults to1. - onEditingChanged:
A closure that’s called when editing begins and ends. For example, on iOS, the user may touch and hold the increment or decrement buttons on a
Stepperwhich causes the execution of theonEditingChangedclosure at the start and end of the gesture.
Discussion
Use Stepper(_:value:step:onEditingChanged:) to create a stepper with a custom title that increments or decrements a binding to value by the step size you specify.
In the example below, the stepper increments or decrements the binding value by 5 each time the user clicks or taps on the control’s increment or decrement buttons, respectively:
struct StepperView: View {
@State private var value = 1
let step = 5
var body: some View {
Stepper("Current value: \(value), step: \(step)",
value: $value,
step: step)
.padding(10)
}
}[Image]