on master help sign in
Add indication for limit. Closes #2.
commit2ef69cc5e8f1571c8f4d849adba62a4e0132ef95 authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateFri 3 Jul 2015, 17:38 (11 years ago) parentc4bdefb
2 files changed+25−12
GMStepper/GMStepper/Base.lproj/Main.storyboard−6 GMStepper/GMStepper/GMStepper.swift+25−6
GMStepper/GMStepper/Base.lproj/Main.storyboard−6
@@ -25,12 +25,6 @@
2525 <constraint firstAttribute="height" constant="44" id="mzJ-k6-SLm"/>
2626 </constraints>
2727 <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>
3428 <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
3529 <real key="value" value="4"/>
3630 </userDefinedRuntimeAttribute>
GMStepper/GMStepper/GMStepper.swift+25−6
@@ -96,6 +96,9 @@ import UIKit
9696 private let labelSlideLength: CGFloat = 5
9797 private let labelSlideDuration: NSTimeInterval = 0.1
9898
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+
99102 private let leftButton = UIButton()
100103 private let rightButton = UIButton()
101104 private let label = UILabel()
@@ -147,19 +150,27 @@ import UIKit
147150 }
148151
149152 @objc private func leftButtonTapped(button: UIButton) {
150− value -= 1
151− animateSlideLeft()
153+ if value == minimumValue {
154+ animateLimitHitForButton(leftButton)
155+ } else {
156+ value -= 1
157+ animateSlideLeft()
158+ }
152159 }
153160
154161 @objc private func rightButtonTapped(button: UIButton) {
155− value += 1
156− animateSlideRight()
162+ if value == maximumValue {
163+ animateLimitHitForButton(rightButton)
164+ } else {
165+ value += 1
166+ animateSlideRight()
167+ }
157168 }
158169
159170 private func animateSlideLeft() {
160171 UIView.animateWithDuration(labelSlideDuration, animations: {
161172 self.label.center.x -= self.labelSlideLength
162− }, completion : { _ in
173+ }, completion: { _ in
163174 UIView.animateWithDuration(self.labelSlideDuration, animations: {
164175 self.label.center.x += self.labelSlideLength
165176 })
@@ -169,10 +180,18 @@ import UIKit
169180 private func animateSlideRight() {
170181 UIView.animateWithDuration(labelSlideDuration, animations: {
171182 self.label.center.x += self.labelSlideLength
172− }, completion : { _ in
183+ }, completion: { _ in
173184 UIView.animateWithDuration(self.labelSlideDuration, animations: {
174185 self.label.center.x -= self.labelSlideLength
175186 })
176187 })
177188 }
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+ }
178197}