Search code examples
iosuitextfieldswift2uistepper

Start UIStepper from initial value


I have a UIStepper connected to a UITextField. The stepper goes from 0 to 13. Whenever I click the stepper on the plus, I get "1" . I want to start with a 0. I tried many codes, but none of them worked, such as:

@IBAction func stepperAc(sender: AnyObject) {
     if textField.text == "" {
     Stepper.value = 0
     textField.text = 0
   }
}

How can I do that ?


Solution

  • Try this:

    @IBAction func stepperAc(sender: UIStepper) {
     if textField.text == "" {
         sender.value = 0
         textField.text = 0
       }
    }