@@ -11,10 +11,17 @@ import UIKit
11@IBDesignable public class GMStepper: UIControl {
11@IBDesignable public class GMStepper: UIControl {
13 /// Current value of the stepper. Defaults to 0.
13 /// Current value of the stepper. Defaults to 0.
14− @IBInspectable public var value = 0 {
14+ @IBInspectable public var value: Double = 0 {
16 value = min(maximumValue, max(minimumValue, value))
16 value = min(maximumValue, max(minimumValue, value))
18+ let isInteger = floor(value) == value
20+ if showIntegerIfDoubleIsInteger && isInteger {
21+ label.text = String(stringInterpolationSegment: Int(value))
17− label.text = String(value)
23+ label.text = String(stringInterpolationSegment: value)
19 if oldValue != value {
26 if oldValue != value {
20 sendActionsForControlEvents(.ValueChanged)
27 sendActionsForControlEvents(.ValueChanged)
@@ -23,22 +30,27 @@ import UIKit
25 /// Minimum value. Must be less than maximumValue. Defaults to 0.
32 /// Minimum value. Must be less than maximumValue. Defaults to 0.
26− @IBInspectable public var minimumValue: Int = 0 {
33+ @IBInspectable public var minimumValue: Double = 0 {
28 value = min(maximumValue, max(minimumValue, value))
35 value = min(maximumValue, max(minimumValue, value))
32− /// Maximum value. Must be more than minimumValue. Defaults to 10.
39+ /// Maximum value. Must be more than minimumValue. Defaults to 100.
33− @IBInspectable public var maximumValue: Int = 10 {
40+ @IBInspectable public var maximumValue: Double = 100 {
35 value = min(maximumValue, max(minimumValue, value))
42 value = min(maximumValue, max(minimumValue, value))
46+ /// Step/Increment value as in UIStepper. Defaults to 1.
47+ @IBInspectable public var stepValue: Double = 1
39 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
49 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
40 @IBInspectable public var autorepeat: Bool = true
50 @IBInspectable public var autorepeat: Bool = true
52+ @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
42 /// Text on the left button. Be sure that it fits in the button. Defaults to "-".
54 /// Text on the left button. Be sure that it fits in the button. Defaults to "-".
43 @IBInspectable public var leftButtonText: String = "-" {
55 @IBInspectable public var leftButtonText: String = "-" {
@@ -159,7 +171,11 @@ import UIKit
159 lazy var label: UILabel = {
171 lazy var label: UILabel = {
160 let label = UILabel()
172 let label = UILabel()
161 label.textAlignment = .Center
173 label.textAlignment = .Center
174+ if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
162− label.text = String(self.value)
175+ label.text = String(stringInterpolationSegment: Int(self.value))
177+ label.text = String(stringInterpolationSegment: self.value)
163 label.textColor = self.labelTextColor
179 label.textColor = self.labelTextColor
164 label.backgroundColor = self.labelBackgroundColor
180 label.backgroundColor = self.labelBackgroundColor
165 label.font = self.labelFont
181 label.font = self.labelFont
@@ -264,9 +280,9 @@ import UIKit
265 func updateValue() {
281 func updateValue() {
266 if stepperState == .ShouldIncrease {
282 if stepperState == .ShouldIncrease {
267− value += 1
283+ value += stepValue
268 } else if stepperState == .ShouldDecrease {
284 } else if stepperState == .ShouldDecrease {
269− value -= 1
285+ value -= stepValue