Initializer

init(_:value:in:step:onEditingChanged:)

Creates a stepper instance that increments and decrements a binding to a value, by a step size and within a closed range that you provide.

Declaration 宣言

init<V>(_ titleKey: LocalizedStringKey, value: Binding<V>, in bounds: ClosedRange<V>, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V : Strideable
Available when Label is Text. LabelTextである時に利用可能です。

Parameters パラメータ

titleKey

The key for the stepper’s localized title describing the purpose of the stepper.

value

A Binding to a value that your provide.

bounds

A closed range that describes the upper and lower bounds permitted by the stepper.

step

The amount to increment or decrement value each time the user clicks or taps the stepper’s increment or decrement button, respectively. Defaults to 1.

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 Stepper which causes the execution of the onEditingChanged closure at the start and end of the gesture.

Discussion 議論

Use Stepper(_:value:in:step:onEditingChanged:) to create a stepper that increments or decrements a value within a specific range of values by a specific step size. In the example below, a stepper increments or decrements a binding to value over a range of 1...50 by 5 at each press of the stepper’s increment or decrement buttons:


struct StepperView: View {
    @State private var value = 0
    @State private var titleKey = "Stepper"


    let step = 5
    let range = 1...50


    var body: some View {
        VStack(spacing: 20) {
            Text("Current Stepper Value: \(value)")
            Stepper(titleKey, value: $value, in: range, step: step)
        }
    }
}

A view displaying a stepper that increments or decrements within a

See Also 参照

Creating a Stepper Over a Range