One Logo Pool Ball
SwiftUI · IOS API REFERENCE

Slider

struct · iOS 13.0+ · SDK 27.1

nonisolated struct Slider<Label, ValueLabel> where Label : View, ValueLabel : View

A control for selecting a value from a bounded linear range of values. A slider consists of a "thumb" image that the user moves between two extremes of a linear "track". The ends of the track represent the minimum and maximum possible values. As the user moves the thumb, the slider updates its bound value. The following example shows a slider bound to the value `speed`. As the slider updates this value, a bound ``Text`` view shows the value updating. The `onEditingChanged` closure passed to the slider receives callbacks when the user drags the slider. The example uses this to change the color of the value text. @State private var speed = 50.0 @State private var isEditing = false var body: some View { VStack { Slider( value: $speed, in: 0...100, onEditingChanged: { editing in isEditing = editing } ) Text("\(speed)") .foregroundColor(isEditing ? .red : .blue) } } ![An unlabeled slider, with its thumb about one third of the way from the minimum extreme. Below, a blue label displays the value 33.045977.](SwiftUI-Slider-simple.png) You can also use a `step` parameter to provide incremental steps along the path of the slider. For example, if you have a slider with a range of `0` to `100`, and you set the `step` value to `5`, the slider's increments would be `0`, `5`, `10`, and so on. The following example shows this approach, and also adds optional minimum and maximum value labels. @State private var speed = 50.0 @State private var isEditing = false var body: some View { Slider( value: $speed, in: 0...100, step: 5 ) { Text("Speed") } minimumValueLabel: { Text("0") } maximumValueLabel: { Text("100") } onEditingChanged: { editing in isEditing = editing } Text("\(speed)") .foregroundColor(isEditing ? .red : .blue) } ![A slider with labels show minimum and maximum values of 0 and 100, respectively, with its thumb most of the way to the maximum extreme. Below, a blue label displays the value 85.000000.](SwiftUI-Slider-withStepAndLabels.png) The slider also uses the `step` to increase or decrease the value when a VoiceOver user adjusts the slider with voice commands.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

12 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Slider.body

This protocol needs associated types that cannot yet cross the bridge.

Slider.init(value:in:label:minimumValueLabel:maximumValueLabel:onEditingChanged:)

callback cannot propagate synchronous failure

Slider.init(value:in:step:label:minimumValueLabel:maximumValueLabel:onEditingChanged:)

callback cannot propagate synchronous failure

Slider.init(value:in:label:onEditingChanged:)

callback cannot propagate synchronous failure

Slider.init(value:in:step:label:onEditingChanged:)

callback cannot propagate synchronous failure

Slider.init(value:in:onEditingChanged:minimumValueLabel:maximumValueLabel:label:)

callback cannot propagate synchronous failure

Slider.init(value:in:step:onEditingChanged:minimumValueLabel:maximumValueLabel:label:)

callback cannot propagate synchronous failure

Slider.init(value:in:onEditingChanged:label:)

callback cannot propagate synchronous failure

Slider.init(value:in:step:onEditingChanged:label:)

callback cannot propagate synchronous failure

Slider.init(value:in:neutralValue:enabledBounds:label:currentValueLabel:minimumValueLabel:maximumValueLabel:onEditingChanged:)

callback cannot propagate synchronous failure

Slider.init(value:in:neutralValue:enabledBounds:label:currentValueLabel:minimumValueLabel:maximumValueLabel:ticks:onEditingChanged:)

This declaration needs Swift generic type arguments. (no canonical witness for V)

Slider.init(value:in:step:neutralValue:enabledBounds:label:currentValueLabel:minimumValueLabel:maximumValueLabel:tick:onEditingChanged:)

callback cannot propagate synchronous failure

All SwiftUI types →