-
Notifications
You must be signed in to change notification settings - Fork 31
/
KWStepper+Chaining.swift
161 lines (121 loc) · 3.74 KB
/
KWStepper+Chaining.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//
// KWStepper.swift
// Created by Kyle Weiner on 1/22/17.
// https://github.com/kyleweiner/KWStepper
//
import Foundation
public extension KWStepper {
// MARK: - Configuration Methods
/// Sets the stepper's `autoRepeat` value.
@discardableResult
func autoRepeat(_ value: Bool) -> Self {
autoRepeat = value
return self
}
/// Sets the stepper's `autoRepeatInterval`.
@discardableResult
func autoRepeatInterval(_ value: TimeInterval) -> Self {
autoRepeatInterval = value
return self
}
/// Sets the stepper's `wraps` value.
@discardableResult
func wraps(_ value: Bool) -> Self {
wraps = value
return self
}
/// Sets the stepper's `minimumValue`.
@discardableResult
func minimumValue(_ value: Double) -> Self {
minimumValue = value
return self
}
/// Sets the stepper's `maximumValue`.
@discardableResult
func maximumValue(_ value: Double) -> Self {
maximumValue = value
return self
}
/// Sets the stepper's `decrementStepValue`.
@discardableResult
func decrementStepValue(_ value: Double) -> Self {
decrementStepValue = value
return self
}
/// Sets the stepper's `incrementStepValue`.
@discardableResult
func incrementStepValue(_ value: Double) -> Self {
incrementStepValue = value
return self
}
/// Sets the stepper's `roundingBehavior`.
@discardableResult
func roundingBehavior(_ value: Double) -> Self {
self.roundingBehavior = roundingBehavior
return self
}
/// Sets the stepper's `delegate`.
@discardableResult
func delegate(_ value: KWStepperDelegate?) -> Self {
delegate = value
return self
}
/// Sets the stepper's `value`.
@discardableResult
func value(_ value: Double) -> Self {
self.value = value
return self
}
// MARK: - Callback Methods
/// Sets the stepper's `valueChangedCallback`.
@discardableResult
func valueChanged(_ callback: KWStepperCallback?) -> Self {
valueChangedCallback = callback
return self
}
/// Sets the stepper's `decrementCallback`.
@discardableResult
func didDecrement(_ callback: KWStepperCallback?) -> Self {
decrementCallback = callback
return self
}
/// Sets the stepper's `incrementCallback`.
@discardableResult
func didIncrement(_ callback: KWStepperCallback?) -> Self {
incrementCallback = callback
return self
}
/// Sets the stepper's `maxValueClampedCallback`.
@discardableResult
func maxValueClamped(_ callback: KWStepperCallback?) -> Self {
maxValueClampedCallback = callback
return self
}
/// Sets the stepper's `minValueClampedCallback`.
@discardableResult
func minValueClamped(_ callback: KWStepperCallback?) -> Self {
minValueClampedCallback = callback
return self
}
/// Sets the stepper's `longPressEndedCallback`.
@discardableResult
func longPressEnded(_ callback: KWStepperCallback?) -> Self {
longPressEndedCallback = callback
return self
}
// MARK: - Convenience Methods
/// Sets the stepper's `decrementStepValue` and `incrementStepValue`.
@discardableResult
func stepValue(_ value: Double) -> Self {
decrementStepValue = value
incrementStepValue = value
return self
}
/// Sets the stepper's `maxValueClampedCallback` and `minValueClampedCallback`.
@discardableResult
func valueClamped(_ callback: @escaping KWStepperCallback) -> Self {
maxValueClampedCallback = callback
minValueClampedCallback = callback
return self
}
}