@@ -9,6 +9,8 @@
9import UIKit
9import UIKit
11@IBDesignable public class GMStepper: UIControl {
11@IBDesignable public class GMStepper: UIControl {
13+ /// Current value of the stepper. Defaults to 0.
12 public var value = 0 {
14 public var value = 0 {
14 value = min(maximumValue, max(minimumValue, value))
16 value = min(maximumValue, max(minimumValue, value))
@@ -20,30 +22,35 @@ import UIKit
25+ /// Minimum value. Must be less than maximumValue. Defaults to 0.
23 @IBInspectable public var minimumValue: Int = 0 {
26 @IBInspectable public var minimumValue: Int = 0 {
32+ /// Maximum value. Must be more than minimumValue. Defaults to 10.
29 @IBInspectable public var maximumValue: Int = 10 {
33 @IBInspectable public var maximumValue: Int = 10 {
39+ /// Text on the left button. Be sure that it fits in the button. Defaults to "-".
35 @IBInspectable public var leftButtonText: String = "-" {
40 @IBInspectable public var leftButtonText: String = "-" {
37 leftButton.setTitle(leftButtonText, forState: .Normal)
42 leftButton.setTitle(leftButtonText, forState: .Normal)
46+ /// Text on the right button. Be sure that it fits in the button. Defaults to "+".
41 @IBInspectable public var rightButtonText: String = "+" {
47 @IBInspectable public var rightButtonText: String = "+" {
43 rightButton.setTitle(rightButtonText, forState: .Normal)
49 rightButton.setTitle(rightButtonText, forState: .Normal)
53+ /// Text color of the buttons. Defaults to white.
47 @IBInspectable public var buttonsTextColor: UIColor = UIColor.whiteColor() {
54 @IBInspectable public var buttonsTextColor: UIColor = UIColor.whiteColor() {
49 for button in [leftButton, rightButton] {
56 for button in [leftButton, rightButton] {
@@ -52,6 +59,7 @@ import UIKit
62+ /// Background color of the buttons. Defaults to dark blue.
55 @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
63 @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
57 for button in [leftButton, rightButton] {
65 for button in [leftButton, rightButton] {
@@ -61,6 +69,7 @@ import UIKit
72+ /// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
64 public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
73 public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
66 for button in [leftButton, rightButton] {
75 for button in [leftButton, rightButton] {
@@ -69,24 +78,28 @@ import UIKit
81+ /// Text color of the middle label. Defaults to white.
72 @IBInspectable public var labelTextColor: UIColor = UIColor.whiteColor() {
82 @IBInspectable public var labelTextColor: UIColor = UIColor.whiteColor() {
74 label.textColor = labelTextColor
84 label.textColor = labelTextColor
88+ /// Text color of the middle label. Defaults to lighter blue.
78 @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
89 @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
80 label.backgroundColor = labelBackgroundColor
91 label.backgroundColor = labelBackgroundColor
95+ /// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
84 public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
96 public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
86 label.font = labelFont
98 label.font = labelFont
102+ /// Corner radius of the stepper's layer. Defaults to 4.0.
90 @IBInspectable public var cornerRadius: CGFloat = 4.0 {
103 @IBInspectable public var cornerRadius: CGFloat = 4.0 {
92 layer.cornerRadius = cornerRadius
105 layer.cornerRadius = cornerRadius
@@ -94,6 +107,7 @@ import UIKit
110+ /// 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.
97 @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
111 @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
99 labelWidthWeight = min(1, max(0, labelWidthWeight))
113 labelWidthWeight = min(1, max(0, labelWidthWeight))
@@ -101,10 +115,18 @@ import UIKit
119+ Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
104 private let labelSlideLength: CGFloat = 5
121 private let labelSlideLength: CGFloat = 5
123+ /// Duration of the sliding animation
105 private let labelSlideDuration: NSTimeInterval = 0.1
124 private let labelSlideDuration: NSTimeInterval = 0.1
126+ /// Duration of the flashing animation when the value hits the limit.
107 private let limitHitAnimationDuration: NSTimeInterval = 0.1
127 private let limitHitAnimationDuration: NSTimeInterval = 0.1
129+ /// Color of the flashing animation on the buttons in case the value hit the limit.
108 @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
130 @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
110 private let leftButton = UIButton()
132 private let leftButton = UIButton()