@@ -133,6 +133,15 @@ import UIKit
133133 private let rightButton = UIButton()
134134 private let label = UILabel()
135135
136+ private var labelOriginalCenter: CGPoint!
137+ private var labelMaximumCenterX: CGFloat!
138+ private var labelMinimumCenterX: CGFloat!
139+
140+ private enum LabelPanState {
141+ case Stale, HitRightEdge, HitLeftEdge
142+ }
143+ private var panState = LabelPanState.Stale
144+
136145 required public init(coder aDecoder: NSCoder) {
137146 super.init(coder: aDecoder)
138147 setup()
@@ -168,6 +177,10 @@ import UIKit
168177 backgroundColor = buttonsBackgroundColor
169178 layer.cornerRadius = cornerRadius
170179 clipsToBounds = true
180+
181+ let panRecognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
182+ label.userInteractionEnabled = true
183+ label.addGestureRecognizer(panRecognizer)
171184 }
172185
173186 public override func layoutSubviews() {
@@ -177,6 +190,10 @@ import UIKit
177190 leftButton.frame = CGRect(x: 0, y: 0, width: buttonWidth, height: bounds.size.height)
178191 label.frame = CGRect(x: buttonWidth, y: 0, width: labelWidth, height: bounds.size.height)
179192 rightButton.frame = CGRect(x: labelWidth + buttonWidth, y: 0, width: buttonWidth, height: bounds.size.height)
193+
194+ labelMaximumCenterX = label.center.x + labelSlideLength
195+ labelMinimumCenterX = label.center.x - labelSlideLength
196+ labelOriginalCenter = label.center
180197 }
181198
182199 @objc private func leftButtonTapped(button: UIButton) {
@@ -224,4 +241,65 @@ import UIKit
224241 button.backgroundColor = self.buttonsBackgroundColor
225242 })
226243 }
244+
245+ @objc private func handlePan(gesture: UIPanGestureRecognizer) {
246+ switch gesture.state {
247+ case .Changed:
248+ var translation = gesture.translationInView(label)
249+ gesture.setTranslation(CGPointZero, inView: label)
250+
251+ var slidingRight = gesture.velocityInView(label).x > 0
252+ var slidingLeft = gesture.velocityInView(label).x < 0
253+
254+ // Move the label with pan
255+ if slidingRight {
256+ label.center.x = min(labelMaximumCenterX, label.center.x + translation.x)
257+ } else if slidingLeft {
258+ label.center.x = max(labelMinimumCenterX, label.center.x + translation.x)
259+ }
260+
261+ // When the label hits the edges, increase/decrease value and change button backgrounds
262+ if label.center.x == labelMaximumCenterX {
263+
264+ // Increase only once for each pan gesture
265+ if panState != .HitRightEdge {
266+ value += 1
267+ panState = .HitRightEdge
268+ }
269+
270+ if value == maximumValue {
271+ rightButton.backgroundColor = self.limitHitAnimationColor
272+ }
273+ } else if label.center.x == labelMinimumCenterX {
274+
275+ if panState != .HitLeftEdge {
276+ value -= 1
277+ panState = .HitLeftEdge
278+ }
279+
280+ if value == minimumValue {
281+ leftButton.backgroundColor = self.limitHitAnimationColor
282+ }
283+ } else {
284+ leftButton.backgroundColor = buttonsBackgroundColor
285+ rightButton.backgroundColor = buttonsBackgroundColor
286+ }
287+
288+ case .Ended:
289+ reset()
290+ default:
291+ break
292+ }
293+ }
294+
295+ private func reset() {
296+ panState = .Stale
297+
298+ UIView.animateWithDuration(self.labelSlideDuration, animations: {
299+ self.label.center = self.labelOriginalCenter
300+ self.rightButton.backgroundColor = self.buttonsBackgroundColor
301+ self.leftButton.backgroundColor = self.buttonsBackgroundColor
302+ })
303+ }
304+
227305}