@@ -11,7 +11,7 @@ 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: Double = 0 {
14+ @objc @IBInspectable public var value: Double = 0 {
16 value = min(maximumValue, max(minimumValue, value))
16 value = min(maximumValue, max(minimumValue, value))
@@ -37,44 +37,44 @@ import UIKit
39 /// Minimum value. Must be less than maximumValue. Defaults to 0.
39 /// Minimum value. Must be less than maximumValue. Defaults to 0.
40− @IBInspectable public var minimumValue: Double = 0 {
40+ @objc @IBInspectable public var minimumValue: Double = 0 {
42 value = min(maximumValue, max(minimumValue, value))
42 value = min(maximumValue, max(minimumValue, value))
46 /// Maximum value. Must be more than minimumValue. Defaults to 100.
46 /// Maximum value. Must be more than minimumValue. Defaults to 100.
47− @IBInspectable public var maximumValue: Double = 100 {
47+ @objc @IBInspectable public var maximumValue: Double = 100 {
49 value = min(maximumValue, max(minimumValue, value))
49 value = min(maximumValue, max(minimumValue, value))
53 /// Step/Increment value as in UIStepper. Defaults to 1.
53 /// Step/Increment value as in UIStepper. Defaults to 1.
54− @IBInspectable public var stepValue: Double = 1
54+ @objc @IBInspectable public var stepValue: Double = 1
56 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
56 /// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
57− @IBInspectable public var autorepeat: Bool = true
57+ @objc @IBInspectable public var autorepeat: Bool = true
59 /// If the value is integer, it is shown without floating point.
59 /// If the value is integer, it is shown without floating point.
60− @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
60+ @objc @IBInspectable public var showIntegerIfDoubleIsInteger: Bool = true
62 /// Text on the left button. Be sure that it fits in the button. Defaults to "−".
62 /// Text on the left button. Be sure that it fits in the button. Defaults to "−".
63− @IBInspectable public var leftButtonText: String = "−" {
63+ @objc @IBInspectable public var leftButtonText: String = "−" {
65 leftButton.setTitle(leftButtonText, for: .normal)
65 leftButton.setTitle(leftButtonText, for: .normal)
69 /// Text on the right button. Be sure that it fits in the button. Defaults to "+".
69 /// Text on the right button. Be sure that it fits in the button. Defaults to "+".
70− @IBInspectable public var rightButtonText: String = "+" {
70+ @objc @IBInspectable public var rightButtonText: String = "+" {
72 rightButton.setTitle(rightButtonText, for: .normal)
72 rightButton.setTitle(rightButtonText, for: .normal)
76 /// Text color of the buttons. Defaults to white.
76 /// Text color of the buttons. Defaults to white.
77− @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
77+ @objc @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
79 for button in [leftButton, rightButton] {
79 for button in [leftButton, rightButton] {
80 button.setTitleColor(buttonsTextColor, for: .normal)
80 button.setTitleColor(buttonsTextColor, for: .normal)
@@ -83,7 +83,7 @@ import UIKit
85 /// Background color of the buttons. Defaults to dark blue.
85 /// Background color of the buttons. Defaults to dark blue.
86− @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
86+ @objc @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
88 for button in [leftButton, rightButton] {
88 for button in [leftButton, rightButton] {
89 button.backgroundColor = buttonsBackgroundColor
89 button.backgroundColor = buttonsBackgroundColor
@@ -93,7 +93,7 @@ import UIKit
95 /// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
95 /// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
96− public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
96+ @objc public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
98 for button in [leftButton, rightButton] {
98 for button in [leftButton, rightButton] {
99 button.titleLabel?.font = buttonsFont
99 button.titleLabel?.font = buttonsFont
@@ -102,28 +102,35 @@ import UIKit
104 /// Text color of the middle label. Defaults to white.
104 /// Text color of the middle label. Defaults to white.
105− @IBInspectable public var labelTextColor: UIColor = UIColor.white {
105+ @objc @IBInspectable public var labelTextColor: UIColor = UIColor.white {
107 label.textColor = labelTextColor
107 label.textColor = labelTextColor
111 /// Text color of the middle label. Defaults to lighter blue.
111 /// Text color of the middle label. Defaults to lighter blue.
112− @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
112+ @objc @IBInspectable public var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1) {
114 label.backgroundColor = labelBackgroundColor
114 label.backgroundColor = labelBackgroundColor
118 /// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
118 /// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
119− public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
119+ @objc public var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)! {
121 label.font = labelFont
121 label.font = labelFont
124+ /// Corner radius of the middle label. Defaults to 0.
125+ @objc @IBInspectable public var labelCornerRadius: CGFloat = 0 {
127+ label.layer.cornerRadius = labelCornerRadius
125 /// Corner radius of the stepper's layer. Defaults to 4.0.
132 /// Corner radius of the stepper's layer. Defaults to 4.0.
126− @IBInspectable public var cornerRadius: CGFloat = 4.0 {
133+ @objc @IBInspectable public var cornerRadius: CGFloat = 4.0 {
128 layer.cornerRadius = cornerRadius
135 layer.cornerRadius = cornerRadius
129 clipsToBounds = true
136 clipsToBounds = true
@@ -131,7 +138,7 @@ import UIKit
133 /// Border width of the stepper and middle label's layer. Defaults to 0.0.
140 /// Border width of the stepper and middle label's layer. Defaults to 0.0.
134− @IBInspectable public var borderWidth: CGFloat = 0.0 {
141+ @objc @IBInspectable public var borderWidth: CGFloat = 0.0 {
136 layer.borderWidth = borderWidth
143 layer.borderWidth = borderWidth
137 label.layer.borderWidth = borderWidth
144 label.layer.borderWidth = borderWidth
@@ -139,7 +146,7 @@ import UIKit
141 /// Color of the border of the stepper and middle label's layer. Defaults to clear color.
148 /// Color of the border of the stepper and middle label's layer. Defaults to clear color.
142− @IBInspectable public var borderColor: UIColor = UIColor.clear {
149+ @objc @IBInspectable public var borderColor: UIColor = UIColor.clear {
144 layer.borderColor = borderColor.cgColor
151 layer.borderColor = borderColor.cgColor
145 label.layer.borderColor = borderColor.cgColor
152 label.layer.borderColor = borderColor.cgColor
@@ -147,7 +154,7 @@ import UIKit
149 /// 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.
156 /// 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.
150− @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
157+ @objc @IBInspectable public var labelWidthWeight: CGFloat = 0.5 {
152 labelWidthWeight = min(1, max(0, labelWidthWeight))
159 labelWidthWeight = min(1, max(0, labelWidthWeight))
153 setNeedsLayout()
160 setNeedsLayout()
@@ -155,7 +162,7 @@ import UIKit
157 /// Color of the flashing animation on the buttons in case the value hit the limit.
164 /// Color of the flashing animation on the buttons in case the value hit the limit.
158− @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
165+ @objc @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
161 Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
168 Width of the sliding animation. When buttons clicked, the middle label does a slide animation towards to the clicked button. Defaults to 5.
@@ -177,6 +184,7 @@ import UIKit
177 button.addTarget(self, action: #selector(GMStepper.leftButtonTouchDown), for: .touchDown)
184 button.addTarget(self, action: #selector(GMStepper.leftButtonTouchDown), for: .touchDown)
178 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
185 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
179 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
186 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
187+ button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchCancel)
180 return button
188 return button
@@ -189,6 +197,7 @@ import UIKit
189 button.addTarget(self, action: #selector(GMStepper.rightButtonTouchDown), for: .touchDown)
197 button.addTarget(self, action: #selector(GMStepper.rightButtonTouchDown), for: .touchDown)
190 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
198 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
191 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
199 button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
200+ button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchCancel)
192 return button
201 return button
@@ -203,6 +212,8 @@ import UIKit
203 label.textColor = self.labelTextColor
212 label.textColor = self.labelTextColor
204 label.backgroundColor = self.labelBackgroundColor
213 label.backgroundColor = self.labelBackgroundColor
205 label.font = self.labelFont
214 label.font = self.labelFont
215+ label.layer.cornerRadius = self.labelCornerRadius
216+ label.layer.masksToBounds = true
206 label.isUserInteractionEnabled = true
217 label.isUserInteractionEnabled = true
207 let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GMStepper.handlePan))
218 let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GMStepper.handlePan))
208 panRecognizer.maximumNumberOfTouches = 1
219 panRecognizer.maximumNumberOfTouches = 1
@@ -234,7 +245,7 @@ import UIKit
237− public var items : [String] = [] {
248+ @objc public var items : [String] = [] {
239 let isInteger = floor(value) == value
250 let isInteger = floor(value) == value
@@ -280,12 +291,12 @@ import UIKit
283− required public init?(coder aDecoder: NSCoder) {
294+ @objc required public init?(coder aDecoder: NSCoder) {
284 super.init(coder: aDecoder)
295 super.init(coder: aDecoder)
288− public override init(frame: CGRect) {
299+ @objc public override init(frame: CGRect) {
289 super.init(frame: frame)
300 super.init(frame: frame)
@@ -298,6 +309,7 @@ import UIKit
298 backgroundColor = buttonsBackgroundColor
309 backgroundColor = buttonsBackgroundColor
299 layer.cornerRadius = cornerRadius
310 layer.cornerRadius = cornerRadius
300 clipsToBounds = true
311 clipsToBounds = true
312+ labelOriginalCenter = label.center
302 NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
314 NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
@@ -344,7 +356,7 @@ import UIKit
345// MARK: Pan Gesture
357// MARK: Pan Gesture
346extension GMStepper {
358extension GMStepper {
347− func handlePan(gesture: UIPanGestureRecognizer) {
359+ @objc func handlePan(gesture: UIPanGestureRecognizer) {
348 switch gesture.state {
360 switch gesture.state {
349 case .began:
361 case .began:
350 leftButton.isEnabled = false
362 leftButton.isEnabled = false
@@ -394,7 +406,7 @@ extension GMStepper {
397− func reset() {
409+ @objc func reset() {
398 panState = .Stable
410 panState = .Stable
399 stepperState = .Stable
411 stepperState = .Stable
400 resetTimer()
412 resetTimer()
@@ -413,7 +425,7 @@ extension GMStepper {
414// MARK: Button Events
426// MARK: Button Events
415extension GMStepper {
427extension GMStepper {
416− func leftButtonTouchDown(button: UIButton) {
428+ @objc func leftButtonTouchDown(button: UIButton) {
417 rightButton.isEnabled = false
429 rightButton.isEnabled = false
418 label.isUserInteractionEnabled = false
430 label.isUserInteractionEnabled = false
419 resetTimer()
431 resetTimer()
@@ -427,7 +439,7 @@ extension GMStepper {
430− func rightButtonTouchDown(button: UIButton) {
442+ @objc func rightButtonTouchDown(button: UIButton) {
431 leftButton.isEnabled = false
443 leftButton.isEnabled = false
432 label.isUserInteractionEnabled = false
444 label.isUserInteractionEnabled = false
433 resetTimer()
445 resetTimer()
@@ -440,7 +452,7 @@ extension GMStepper {
443− func buttonTouchUp(button: UIButton) {
455+ @objc func buttonTouchUp(button: UIButton) {
@@ -485,7 +497,7 @@ extension GMStepper {
486// MARK: Timer
498// MARK: Timer
487extension GMStepper {
499extension GMStepper {
488− func handleTimerFire(timer: Timer) {
500+ @objc func handleTimerFire(timer: Timer) {
489 timerFireCount += 1
501 timerFireCount += 1
491 if timerFireCount % timerFireCountModulo == 0 {
503 if timerFireCount % timerFireCountModulo == 0 {