on master help sign in
Add sliding label. Closes #3
c4bdefbGunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard+1−1
@@ -1,5 +1,5 @@
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2−<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
2+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
3 <dependencies>
3 <dependencies>
4 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
4 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
5 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
5 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
GMStepper/GMStepper/GMStepper.swift+26
@@ -93,6 +93,9 @@ import UIKit
93 }
93 }
94 }
94 }
95
95
96+ private let labelSlideLength: CGFloat = 5
97+ private let labelSlideDuration: NSTimeInterval = 0.1
98+
96 private let leftButton = UIButton()
99 private let leftButton = UIButton()
97 private let rightButton = UIButton()
100 private let rightButton = UIButton()
98 private let label = UILabel()
101 private let label = UILabel()
@@ -129,6 +132,7 @@ import UIKit
129 label.font = labelFont
132 label.font = labelFont
130 addSubview(label)
133 addSubview(label)
131
134
135+ backgroundColor = buttonsBackgroundColor
132 layer.cornerRadius = cornerRadius
136 layer.cornerRadius = cornerRadius
133 clipsToBounds = true
137 clipsToBounds = true
134 }
138 }
@@ -144,9 +148,31 @@ import UIKit
144
148
145 @objc private func leftButtonTapped(button: UIButton) {
149 @objc private func leftButtonTapped(button: UIButton) {
146 value -= 1
150 value -= 1
151+ animateSlideLeft()
147 }
152 }
148
153
149 @objc private func rightButtonTapped(button: UIButton) {
154 @objc private func rightButtonTapped(button: UIButton) {
150 value += 1
155 value += 1
156+ animateSlideRight()
157+ }
158+
159+ private func animateSlideLeft() {
160+ UIView.animateWithDuration(labelSlideDuration, animations: {
161+ self.label.center.x -= self.labelSlideLength
162+ }, completion : { _ in
163+ UIView.animateWithDuration(self.labelSlideDuration, animations: {
164+ self.label.center.x += self.labelSlideLength
165+ })
166+ })
167+ }
168+
169+ private func animateSlideRight() {
170+ UIView.animateWithDuration(labelSlideDuration, animations: {
171+ self.label.center.x += self.labelSlideLength
172+ }, completion : { _ in
173+ UIView.animateWithDuration(self.labelSlideDuration, animations: {
174+ self.label.center.x -= self.labelSlideLength
175+ })
176+ })
151 }
177 }
152}
178}