on master help sign in
Add indication for limit. Closes #2.
2ef69ccGunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard−6
@@ -25,12 +25,6 @@
25 <constraint firstAttribute="height" constant="44" id="mzJ-k6-SLm"/>
25 <constraint firstAttribute="height" constant="44" id="mzJ-k6-SLm"/>
26 </constraints>
26 </constraints>
27 <userDefinedRuntimeAttributes>
27 <userDefinedRuntimeAttributes>
28− <userDefinedRuntimeAttribute type="number" keyPath="minimumValue">
29− <integer key="value" value="0"/>
30− </userDefinedRuntimeAttribute>
31− <userDefinedRuntimeAttribute type="number" keyPath="maximumValue">
32− <integer key="value" value="9"/>
33− </userDefinedRuntimeAttribute>
34 <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
28 <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
35 <real key="value" value="4"/>
29 <real key="value" value="4"/>
36 </userDefinedRuntimeAttribute>
30 </userDefinedRuntimeAttribute>
GMStepper/GMStepper/GMStepper.swift+25−6
@@ -96,6 +96,9 @@ import UIKit
96 private let labelSlideLength: CGFloat = 5
96 private let labelSlideLength: CGFloat = 5
97 private let labelSlideDuration: NSTimeInterval = 0.1
97 private let labelSlideDuration: NSTimeInterval = 0.1
98
98
99+ private let limitHitAnimationDuration: NSTimeInterval = 0.1
100+ @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.23, green:0.3, blue:0.51, alpha:1)
101+
99 private let leftButton = UIButton()
102 private let leftButton = UIButton()
100 private let rightButton = UIButton()
103 private let rightButton = UIButton()
101 private let label = UILabel()
104 private let label = UILabel()
@@ -147,19 +150,27 @@ import UIKit
147 }
150 }
148
151
149 @objc private func leftButtonTapped(button: UIButton) {
152 @objc private func leftButtonTapped(button: UIButton) {
153+ if value == minimumValue {
154+ animateLimitHitForButton(leftButton)
155+ } else {
150− value -= 1
156+ value -= 1
151− animateSlideLeft()
157+ animateSlideLeft()
158+ }
152 }
159 }
153
160
154 @objc private func rightButtonTapped(button: UIButton) {
161 @objc private func rightButtonTapped(button: UIButton) {
162+ if value == maximumValue {
163+ animateLimitHitForButton(rightButton)
164+ } else {
155− value += 1
165+ value += 1
156− animateSlideRight()
166+ animateSlideRight()
167+ }
157 }
168 }
158
169
159 private func animateSlideLeft() {
170 private func animateSlideLeft() {
160 UIView.animateWithDuration(labelSlideDuration, animations: {
171 UIView.animateWithDuration(labelSlideDuration, animations: {
161 self.label.center.x -= self.labelSlideLength
172 self.label.center.x -= self.labelSlideLength
162− }, completion : { _ in
173+ }, completion: { _ in
163 UIView.animateWithDuration(self.labelSlideDuration, animations: {
174 UIView.animateWithDuration(self.labelSlideDuration, animations: {
164 self.label.center.x += self.labelSlideLength
175 self.label.center.x += self.labelSlideLength
165 })
176 })
@@ -169,10 +180,18 @@ import UIKit
169 private func animateSlideRight() {
180 private func animateSlideRight() {
170 UIView.animateWithDuration(labelSlideDuration, animations: {
181 UIView.animateWithDuration(labelSlideDuration, animations: {
171 self.label.center.x += self.labelSlideLength
182 self.label.center.x += self.labelSlideLength
172− }, completion : { _ in
183+ }, completion: { _ in
173 UIView.animateWithDuration(self.labelSlideDuration, animations: {
184 UIView.animateWithDuration(self.labelSlideDuration, animations: {
174 self.label.center.x -= self.labelSlideLength
185 self.label.center.x -= self.labelSlideLength
175 })
186 })
176 })
187 })
177 }
188 }
189+
190+ private func animateLimitHitForButton(button: UIButton){
191+ UIView.animateWithDuration(limitHitAnimationDuration, animations: {
192+ button.backgroundColor = self.limitHitAnimationColor
193+ }, completion: { _ in
194+ button.backgroundColor = self.buttonsBackgroundColor
195+ })
196+ }
178}
197}