Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions GMStepper/GMStepper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ import UIKit
setNeedsLayout()
}
}

/// Color of the background of buttons in case the value hit the limit.
@objc @IBInspectable public var limitHitBackgroundColor: UIColor? {
didSet {
self.resetButtonsBackGroundColors()
}
}

/// Color of the flashing animation on the buttons in case the value hit the limit.
@objc @IBInspectable public var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)
Expand Down Expand Up @@ -300,6 +307,7 @@ import UIKit
layer.cornerRadius = cornerRadius
clipsToBounds = true
labelOriginalCenter = label.center
self.resetButtonsBackGroundColors()

setupNumberFormatter()

Expand Down Expand Up @@ -397,8 +405,7 @@ extension GMStepper {
stepperState = .Stable
resetTimer()

self.rightButton.backgroundColor = self.buttonsBackgroundColor
self.leftButton.backgroundColor = self.buttonsBackgroundColor
resetButtonsBackGroundColors()
}
case .ended, .cancelled, .failed:
reset()
Expand All @@ -418,10 +425,32 @@ extension GMStepper {

UIView.animate(withDuration: self.labelSlideDuration, animations: {
self.label.center = self.labelOriginalCenter
self.rightButton.backgroundColor = self.buttonsBackgroundColor
self.leftButton.backgroundColor = self.buttonsBackgroundColor
self.resetButtonsBackGroundColors()
})
}

private func resetButtonsBackGroundColors() {

func resetButtonsBackGroundColors(_ buttons:[UIButton]){
for button in buttons {
button.backgroundColor = buttonsBackgroundColor
}
}

if let disableStateColor = self.limitHitBackgroundColor {
if self.value == self.minimumValue {
self.leftButton.backgroundColor = self.limitHitBackgroundColor
resetButtonsBackGroundColors([rightButton])
} else if value == self.maximumValue{
self.rightButton.backgroundColor = self.limitHitBackgroundColor
resetButtonsBackGroundColors([leftButton])
} else {
resetButtonsBackGroundColors([leftButton, rightButton])
}
} else {
resetButtonsBackGroundColors([leftButton, rightButton])
}
}
}

// MARK: Button Events
Expand Down
1 change: 1 addition & 0 deletions GMStepperExample/GMStepperExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ViewController: UIViewController {
@IBOutlet weak var stepper: GMStepper!
override func viewDidLoad() {
super.viewDidLoad()
// stepper.limitHitBackgroundColor = UIColor.purple
stepper.addTarget(self, action: #selector(ViewController.stepperValueChanged), for: .valueChanged)
}

Expand Down