on master help sign in
Clear whitespaces. Closes #10.
commitaa2aa743aa3dd527fce8bab1dff9e8d5c6c9c35a authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateSat 4 Jul 2015, 23:45 (11 years ago) parent10aff6c
2 files changed+31−32
GMStepper/GMStepper.swift+30−30 GMStepperExample/GMStepperExample/ViewController.swift+1−2
GMStepper/GMStepper.swift+30−30
@@ -9,47 +9,47 @@
99import UIKit
1010
1111@IBDesignable public class GMStepper: UIControl {
12−
12+
1313 /// Current value of the stepper. Defaults to 0.
1414 public var value = 0 {
1515 didSet {
1616 value = min(maximumValue, max(minimumValue, value))
1717 label.text = String(value)
18−
18+
1919 if oldValue != value {
2020 sendActionsForControlEvents(.ValueChanged)
2121 }
2222 }
2323 }
24−
24+
2525 /// Minimum value. Must be less than maximumValue. Defaults to 0.
2626 @IBInspectable public var minimumValue: Int = 0 {
2727 didSet {
2828 value = 0
2929 }
3030 }
31−
31+
3232 /// Maximum value. Must be more than minimumValue. Defaults to 10.
3333 @IBInspectable public var maximumValue: Int = 10 {
3434 didSet {
3535 value = 0
3636 }
3737 }
38−
38+
3939 /// Text on the left button. Be sure that it fits in the button. Defaults to "-".
4040 @IBInspectable public var leftButtonText: String = "-" {
4141 didSet {
4242 leftButton.setTitle(leftButtonText, forState: .Normal)
4343 }
4444 }
45−
45+
4646 /// Text on the right button. Be sure that it fits in the button. Defaults to "+".
4747 @IBInspectable public var rightButtonText: String = "+" {
4848 didSet {
4949 rightButton.setTitle(rightButtonText, forState: .Normal)
5050 }
5151 }
52−
52+
5353 /// Text color of the buttons. Defaults to white.
5454 @IBInspectable public var buttonsTextColor: UIColor = UIColor.whiteColor() {
5555 didSet {
@@ -58,7 +58,7 @@ import UIKit
5858 }
5959 }
6060 }
61−
61+
6262 /// Background color of the buttons. Defaults to dark blue.
6363 @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
6464 didSet {
@@ -68,7 +68,7 @@ import UIKit
6868 backgroundColor = buttonsBackgroundColor
6969 }
7070 }
71−
71+
7272 /// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
7373 public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
7474 didSet {
@@ -77,14 +77,14 @@ import UIKit
7777 }
7878 }
7979 }
80−
80+
8181 /// Text color of the middle label. Defaults to white.
8282 @IBInspectable public var labelTextColor: UIColor = UIColor.whiteColor() {
8383 didSet {
8484 label.textColor = labelTextColor
8585 }
8686 }
87−
87+
8888 /// Text color of the middle label. Defaults to lighter blue.
8989 @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
9090 didSet {
@@ -98,7 +98,7 @@ import UIKit
9898 label.font = labelFont
9999 }
100100 }
101−
101+
102102 /// Corner radius of the stepper's layer. Defaults to 4.0.
103103 @IBInspectable public var cornerRadius: CGFloat = 4.0 {
104104 didSet {
@@ -106,7 +106,7 @@ import UIKit
106106 clipsToBounds = true
107107 }
108108 }
109−
109+
110110 /// Percentage of the middle label's width. Must be between 0 and 1. Defaults to 0.5. Be sure that it is wide enough to show the value.
111111 @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
112112 didSet {
@@ -114,35 +114,35 @@ import UIKit
114114 setNeedsLayout()
115115 }
116116 }
117−
117+
118118 /**
119119 Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
120120 */
121121 private let labelSlideLength: CGFloat = 5
122−
122+
123123 /// Duration of the sliding animation
124124 private let labelSlideDuration: NSTimeInterval = 0.1
125−
125+
126126 /// Duration of the flashing animation when the value hits the limit.
127127 private let limitHitAnimationDuration: NSTimeInterval = 0.1
128−
128+
129129 /// Color of the flashing animation on the buttons in case the value hit the limit.
130130 @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
131−
131+
132132 private let leftButton = UIButton()
133133 private let rightButton = UIButton()
134134 private let label = UILabel()
135−
135+
136136 required public init(coder aDecoder: NSCoder) {
137137 super.init(coder: aDecoder)
138138 setup()
139139 }
140−
140+
141141 public override init(frame: CGRect) {
142142 super.init(frame: frame)
143143 setup()
144144 }
145−
145+
146146 private func setup() {
147147 leftButton.setTitle(leftButtonText, forState: .Normal)
148148 leftButton.setTitleColor(buttonsTextColor, forState: .Normal)
@@ -150,35 +150,35 @@ import UIKit
150150 leftButton.titleLabel?.font = buttonsFont
151151 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
152152 addSubview(leftButton)
153−
153+
154154 rightButton.setTitle(rightButtonText, forState: .Normal)
155155 rightButton.setTitleColor(buttonsTextColor, forState: .Normal)
156156 rightButton.backgroundColor = buttonsBackgroundColor
157157 rightButton.titleLabel?.font = buttonsFont
158158 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
159159 addSubview(rightButton)
160−
160+
161161 label.textAlignment = .Center
162162 label.text = String(value)
163163 label.textColor = labelTextColor
164164 label.backgroundColor = labelBackgroundColor
165165 label.font = labelFont
166166 addSubview(label)
167−
167+
168168 backgroundColor = buttonsBackgroundColor
169169 layer.cornerRadius = cornerRadius
170170 clipsToBounds = true
171171 }
172−
172+
173173 public override func layoutSubviews() {
174174 let buttonWidth = bounds.size.width * ((1 - labelWidthWeight) / 2)
175175 let labelWidth = bounds.size.width * labelWidthWeight
176−
176+
177177 leftButton.frame = CGRect(x: 0, y: 0, width: buttonWidth, height: bounds.size.height)
178178 label.frame = CGRect(x: buttonWidth, y: 0, width: labelWidth, height: bounds.size.height)
179179 rightButton.frame = CGRect(x: labelWidth + buttonWidth, y: 0, width: buttonWidth, height: bounds.size.height)
180180 }
181−
181+
182182 @objc private func leftButtonTapped(button: UIButton) {
183183 if value == minimumValue {
184184 animateLimitHitForButton(leftButton)
@@ -196,7 +196,7 @@ import UIKit
196196 animateSlideRight()
197197 }
198198 }
199−
199+
200200 private func animateSlideLeft() {
201201 UIView.animateWithDuration(labelSlideDuration, animations: {
202202 self.label.center.x -= self.labelSlideLength
@@ -206,7 +206,7 @@ import UIKit
206206 })
207207 })
208208 }
209−
209+
210210 private func animateSlideRight() {
211211 UIView.animateWithDuration(labelSlideDuration, animations: {
212212 self.label.center.x += self.labelSlideLength
@@ -216,7 +216,7 @@ import UIKit
216216 })
217217 })
218218 }
219−
219+
220220 private func animateLimitHitForButton(button: UIButton){
221221 UIView.animateWithDuration(limitHitAnimationDuration, animations: {
222222 button.backgroundColor = self.limitHitAnimationColor
GMStepperExample/GMStepperExample/ViewController.swift+1−2
@@ -15,9 +15,8 @@ class ViewController: UIViewController {
1515 super.viewDidLoad()
1616 stepper.addTarget(self, action: "stepperValueChanged:", forControlEvents: .ValueChanged)
1717 }
18−
18+
1919 func stepperValueChanged(stepper: GMStepper) {
2020 println(stepper.value)
2121 }
2222}
23−