Compare commits
No commits in common. "master" and "dev" have entirely different histories.
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "GMStepper"
|
||||
s.version = "2.2.1"
|
||||
s.version = "2.2"
|
||||
s.summary = "A stepper with a sliding label in the middle."
|
||||
s.homepage = "https://github.com/gmertk/GMStepper"
|
||||
s.screenshots = "https://raw.githubusercontent.com/gmertk/GMStepper/master/Screenshots/screenshot_1.gif"
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ import UIKit
|
|||
didSet {
|
||||
value = min(maximumValue, max(minimumValue, value))
|
||||
|
||||
handleIsLimitReached()
|
||||
|
||||
label.text = formattedValue
|
||||
|
||||
if oldValue != value {
|
||||
|
|
@ -37,6 +35,7 @@ import UIKit
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Minimum value. Must be less than maximumValue. Defaults to 0.
|
||||
@objc @IBInspectable public var minimumValue: Double = 0 {
|
||||
didSet {
|
||||
|
|
@ -68,37 +67,29 @@ import UIKit
|
|||
}
|
||||
}
|
||||
|
||||
/// Image on the left button. Defaults to nil.
|
||||
@objc @IBInspectable public var leftButtonImage: UIImage? = nil {
|
||||
/// Text on the left button. Be sure that it fits in the button. Defaults to "−".
|
||||
@objc @IBInspectable public var leftButtonText: String = "−" {
|
||||
didSet {
|
||||
leftButton.setImage(leftButtonImage, for: .normal)
|
||||
leftButton.setTitle(leftButtonText, for: .normal)
|
||||
}
|
||||
}
|
||||
|
||||
/// Image on the right button. Defaults to nil.
|
||||
@objc @IBInspectable public var rightButtonImage: UIImage? = nil {
|
||||
/// Text on the right button. Be sure that it fits in the button. Defaults to "+".
|
||||
@objc @IBInspectable public var rightButtonText: String = "+" {
|
||||
didSet {
|
||||
rightButton.setImage(rightButtonImage, for: .normal)
|
||||
rightButton.setTitle(rightButtonText, for: .normal)
|
||||
}
|
||||
}
|
||||
|
||||
/// Left button content insets. Defaults to ".zero".
|
||||
@objc @IBInspectable public var leftButtonContentInsets: UIEdgeInsets = .zero {
|
||||
/// Text color of the buttons. Defaults to white.
|
||||
@objc @IBInspectable public var buttonsTextColor: UIColor = UIColor.white {
|
||||
didSet {
|
||||
leftButton.contentEdgeInsets = leftButtonContentInsets
|
||||
for button in [leftButton, rightButton] {
|
||||
button.setTitleColor(buttonsTextColor, for: .normal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Right button content insets. Defaults to ".zero".
|
||||
@objc @IBInspectable public var rightButtonContentInsets: UIEdgeInsets = .zero {
|
||||
didSet {
|
||||
rightButton.contentEdgeInsets = rightButtonContentInsets
|
||||
}
|
||||
}
|
||||
|
||||
/// Left button limit opacity. Defaults to "0.4".
|
||||
@objc @IBInspectable public var leftButtonLimitOpacity: CGFloat = 0.4
|
||||
|
||||
/// Background color of the buttons. Defaults to dark blue.
|
||||
@objc @IBInspectable public var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1) {
|
||||
didSet {
|
||||
|
|
@ -109,12 +100,15 @@ import UIKit
|
|||
}
|
||||
}
|
||||
|
||||
/// Label tap closure
|
||||
@objc public var didTouchLabel: ((Double) -> Void)?
|
||||
|
||||
/// Block is called when the minimum is exceeded
|
||||
@objc public var minimumExceeded: (() -> Void)?
|
||||
|
||||
/// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
|
||||
@objc public var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)! {
|
||||
didSet {
|
||||
for button in [leftButton, rightButton] {
|
||||
button.titleLabel?.font = buttonsFont
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Text color of the middle label. Defaults to white.
|
||||
@objc @IBInspectable public var labelTextColor: UIColor = UIColor.white {
|
||||
didSet {
|
||||
|
|
@ -194,8 +188,10 @@ import UIKit
|
|||
|
||||
lazy var leftButton: UIButton = {
|
||||
let button = UIButton()
|
||||
button.setImage(self.leftButtonImage, for: .normal)
|
||||
button.setTitle(self.leftButtonText, for: .normal)
|
||||
button.setTitleColor(self.buttonsTextColor, for: .normal)
|
||||
button.backgroundColor = self.buttonsBackgroundColor
|
||||
button.titleLabel?.font = self.buttonsFont
|
||||
button.addTarget(self, action: #selector(GMStepper.leftButtonTouchDown), for: .touchDown)
|
||||
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
|
||||
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
|
||||
|
|
@ -205,8 +201,10 @@ import UIKit
|
|||
|
||||
lazy var rightButton: UIButton = {
|
||||
let button = UIButton()
|
||||
button.setImage(self.rightButtonImage, for: .normal)
|
||||
button.setTitle(self.rightButtonText, for: .normal)
|
||||
button.setTitleColor(self.buttonsTextColor, for: .normal)
|
||||
button.backgroundColor = self.buttonsBackgroundColor
|
||||
button.titleLabel?.font = self.buttonsFont
|
||||
button.addTarget(self, action: #selector(GMStepper.rightButtonTouchDown), for: .touchDown)
|
||||
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpInside)
|
||||
button.addTarget(self, action: #selector(GMStepper.buttonTouchUp), for: .touchUpOutside)
|
||||
|
|
@ -227,8 +225,6 @@ import UIKit
|
|||
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(GMStepper.handlePan))
|
||||
panRecognizer.maximumNumberOfTouches = 1
|
||||
label.addGestureRecognizer(panRecognizer)
|
||||
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(GMStepper.handleLabelTap))
|
||||
label.addGestureRecognizer(tapRecognizer)
|
||||
return label
|
||||
}()
|
||||
|
||||
|
|
@ -300,7 +296,6 @@ import UIKit
|
|||
addSubview(rightButton)
|
||||
addSubview(label)
|
||||
|
||||
handleIsLimitReached()
|
||||
backgroundColor = buttonsBackgroundColor
|
||||
layer.cornerRadius = cornerRadius
|
||||
clipsToBounds = true
|
||||
|
|
@ -412,10 +407,6 @@ extension GMStepper {
|
|||
}
|
||||
}
|
||||
|
||||
@objc func handleLabelTap() {
|
||||
didTouchLabel?(value)
|
||||
}
|
||||
|
||||
@objc func reset() {
|
||||
panState = .Stable
|
||||
stepperState = .Stable
|
||||
|
|
@ -442,11 +433,11 @@ extension GMStepper {
|
|||
|
||||
if value == minimumValue {
|
||||
animateLimitHitIfNeeded()
|
||||
minimumExceeded?()
|
||||
} else {
|
||||
stepperState = .ShouldDecrease
|
||||
animateSlideLeft()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc func rightButtonTouchDown(button: UIButton) {
|
||||
|
|
@ -528,16 +519,8 @@ extension GMStepper {
|
|||
}
|
||||
}
|
||||
|
||||
private extension GMStepper {
|
||||
|
||||
func handleIsLimitReached() {
|
||||
let isLimitReached = value == minimumValue
|
||||
leftButton.alpha = isLimitReached ? leftButtonLimitOpacity : 1
|
||||
}
|
||||
}
|
||||
|
||||
extension Decimal {
|
||||
|
||||
var significantFractionalDecimalDigits: Int {
|
||||
return max(-exponent, 0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue