on master help sign in
Add sliding label. Closes #3
commitc4bdefb5d0efe5c6feae1568a42dd23e65651e1b authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateFri 3 Jul 2015, 16:24 (11 years ago) parente87e416
2 files changed+27−1
GMStepper/GMStepper/Base.lproj/Main.storyboard+1−1 GMStepper/GMStepper/GMStepper.swift+26
GMStepper/GMStepper/Base.lproj/Main.storyboard+1−1
@@ -1,5 +1,5 @@
11<?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">
33 <dependencies>
44 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
55 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
GMStepper/GMStepper/GMStepper.swift+26
@@ -93,6 +93,9 @@ import UIKit
9393 }
9494 }
9595
96+ private let labelSlideLength: CGFloat = 5
97+ private let labelSlideDuration: NSTimeInterval = 0.1
98+
9699 private let leftButton = UIButton()
97100 private let rightButton = UIButton()
98101 private let label = UILabel()
@@ -129,6 +132,7 @@ import UIKit
129132 label.font = labelFont
130133 addSubview(label)
131134
135+ backgroundColor = buttonsBackgroundColor
132136 layer.cornerRadius = cornerRadius
133137 clipsToBounds = true
134138 }
@@ -144,9 +148,31 @@ import UIKit
144148
145149 @objc private func leftButtonTapped(button: UIButton) {
146150 value -= 1
151+ animateSlideLeft()
147152 }
148153
149154 @objc private func rightButtonTapped(button: UIButton) {
150155 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+ })
151177 }
152178}