gmertk / GMStepper

A stepper with a sliding label in the middle.
https://github.com/gmertk/GMStepper
MIT License
923 stars 114 forks source link

How to know which button tapped Plus or Minus #48

Closed ibhavin closed 4 years ago

ibhavin commented 5 years ago

Is there any way by which can we know that which button tapped Plus(+) or Minus(-). I want to perform specific action when user tapped Minus(-). I have made action of stepper like this:

@IBAction func stepper_Item_Tapped(_ sender: GMStepper) {
    //
}
ibhavin commented 4 years ago

I have changed in GMStepper.swift file:

@objc @IBInspectable public var buttonTapped = ""

@objc func leftButtonTouchDown(button: UIButton) {
    self.buttonTapped = "Minus"
    .
    .
    .
}
@objc func rightButtonTouchDown(button: UIButton) {
    self.buttonTapped = "Plus"
    .
    .
    .
}
@objc func buttonTouchUp(button: UIButton) {
        self.buttonTapped = ""
        reset()
}

In your action:

@IBAction func stepper_Item_Tapped(_ sender: GMStepper) {
    if sender.buttonTapped == "Minus" {
        print("Minus Button Tapped")
    } else sender.buttonTapped == "Plus" {
        print("Plus Button Tapped")        
    }
}

After adding this code clean and run your project. This is not correct way but this small workaround. Hope @gmertk will update repo with nice solution