Skip to content

Commit 361d8bf

Browse files
cilippofiliaSSwiniarskiyangc95
authored
SwiftUI View: Stepper (#1351)
* List image for new PR * up to date list png * Delete swiftui-list.png * Delete list.png * Stepper gif for new PR entry * Stepper md for new PR request * Delete swiftui-list.png * moving swiftui-list in the right folder * Delete swiftui-stepper.gif * updated stepper gif * moved bullet list at end of syntax block * Update stepper.md * Edits to grammer, structure, and wording Co-authored-by: SSwiniarski <[email protected]> Co-authored-by: Christine Yang <[email protected]> Co-authored-by: Christine Yang <[email protected]>
1 parent ca99a80 commit 361d8bf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
Title: 'Stepper'
3+
Description: 'Allows a user to increment and decrement a value.'
4+
Subjects:
5+
- 'Mobile Development'
6+
- 'Computer Science'
7+
Tags:
8+
- 'SwiftUI'
9+
- 'SwiftUI Views'
10+
- 'Views'
11+
- 'Xcode'
12+
CatalogContent:
13+
- 'learn-swift'
14+
- 'paths/build-ios-apps-with-swiftui'
15+
---
16+
17+
The **`Stepper`** is used to give the user precise control over increasing or decreasing a value.
18+
19+
## Syntax
20+
21+
```pseudo
22+
var body: some View {
23+
Stepper(value: Binding<Stridable>, in: ClosedRange<Int/Double>, step: Int/Double) {
24+
Label here
25+
}
26+
Modifiers here
27+
}
28+
```
29+
30+
- The first parameter that `Stepper` takes is a `value`. This parameter needs to be bound to a variable that tracks changes.
31+
- The second parameter, `in`, specifies the minimum and maximum values accepted by the stepper.
32+
- The third parameter, `step`, specifies the amount that `value` should be incremented or decremented by inside the stepper's range.
33+
- A stepper view's shape, color, and text can be edited using [modifiers](https://www.codecademy.com/resources/docs/swiftui/viewmodifier).
34+
35+
## Example
36+
37+
In the example below, `@State` is used to store the mutable integer value. A `Stepper` is used to count the number of people.
38+
39+
```swift
40+
@State var numberOfPeople = 4
41+
42+
var body: some View {
43+
Stepper(value: $numberOfPeople, in: 2...10, step: 1) {
44+
Text("People count: \(numberOfPeople)")
45+
}
46+
.padding()
47+
}
48+
```
49+
50+
This will display the following:
51+
52+
![Stepper](https://raw.githubusercontent.com/Codecademy/docs/main/media/swiftui-stepper.gif)

media/swiftui-stepper.gif

41.4 KB
Loading

0 commit comments

Comments
 (0)