SwiftUI forms: Stepper

Another useful control we can use in forms is the Stepper view, which lets us select a number and gives a – and + button to decrease or increase it.

We link it to the value of a property with a @State property wrapper, in this case counter:
s…


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

Another useful control we can use in forms is the Stepper view, which lets us select a number and gives a - and + button to decrease or increase it.

We link it to the value of a property with a @State property wrapper, in this case counter:

struct ContentView: View {
    @State private var counter = 0

    var body: some View {
        Form {
            Stepper("The counter is \(counter)", value: $counter)
        }
    }
}

You can use the in parameter of Stepper to limit the range of values it can accept:

Stepper("The counter is \(counter)", value: $counter, in: 0...10)

When you reach a limit, the control to increase or decrease will be gray and non-interactive.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2021-09-29T05:00:00+00:00) SwiftUI forms: Stepper. Retrieved from https://www.scien.cx/2021/09/29/swiftui-forms-stepper/

MLA
" » SwiftUI forms: Stepper." flaviocopes.com | Sciencx - Wednesday September 29, 2021, https://www.scien.cx/2021/09/29/swiftui-forms-stepper/
HARVARD
flaviocopes.com | Sciencx Wednesday September 29, 2021 » SwiftUI forms: Stepper., viewed ,<https://www.scien.cx/2021/09/29/swiftui-forms-stepper/>
VANCOUVER
flaviocopes.com | Sciencx - » SwiftUI forms: Stepper. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/29/swiftui-forms-stepper/
CHICAGO
" » SwiftUI forms: Stepper." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/09/29/swiftui-forms-stepper/
IEEE
" » SwiftUI forms: Stepper." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/09/29/swiftui-forms-stepper/. [Accessed: ]
rf:citation
» SwiftUI forms: Stepper | flaviocopes.com | Sciencx | https://www.scien.cx/2021/09/29/swiftui-forms-stepper/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.