-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAQStepper.swift
60 lines (52 loc) · 1.69 KB
/
AQStepper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// AQStepper.swift
// TestingGitLink
//
// Created by Akash Yashavanthrao Shindhe on 27/01/21.
//
import SwiftUI
struct AQStepper: View {
@State private var value = 0
let colors: [Color] = [.orange, .red, .gray, .blue,
.green, .purple, .pink]
func incrementStep() {
value += 1
if value >= colors.count { value = 0 }
}
func decrementStep() {
value -= 1
if value < 0 { value = colors.count - 1 }
}
@State private var items = 0
let step = 5
let range = 1...50
var body: some View {
Form {
SectionView(title: "Stepper", description: "A control that performs increment and decrement actions.",codeSample: ".DefaultToggleStyle") {
Stepper(onIncrement: incrementStep,
onDecrement: decrementStep) {
Text("Value: \(value) Color: \(colors[value].description)")
}
.padding(5)
.background(colors[value])
}
SectionView(title: "Stepper", description: "A control that performs increment and decrement actions.",codeSample: ".DefaultToggleStyle") {
VStack{
Stepper(value: $items,
in: range,
step: step) {
Text("Current: \(items)")
}
.padding(10)
Text("\(range.description) " +
"stepping by \(step)")
}
}
}
}
}
struct AQStepper_Previews: PreviewProvider {
static var previews: some View {
AQStepper()
}
}