How to use Stepper UI control in IOS

Last Updated: October 6, 2017

In this article we will see how to use the Stepper UI control with Swift Programming language

First create a Single View application in XCODE
Then you place the Stepper Control stepper 1 from the Object Library

Place Label ControlĀ label 1 to show the stepper value

Next you can create the Outlet for Stepper and Label

stepper outlet

Now you can create a Action for UIStepper called stepperValueChanged

So your should look like this

    @IBAction func stepperValueChanged(_ sender: UIStepper) {
        
        labelValue.text = Int(sender.value).description
    }

This is the completed code to show the stepper value

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var labelValue: UILabel!
    @IBOutlet weak var stepper: UIStepper!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        stepper.minimumValue = -10
    
        stepper.maximumValue = 10
        stepper.value = -5
    }

    @IBAction func stepperValueChanged(_ sender: UIStepper) {
        
        labelValue.text = Int(sender.value).description
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

Check your final output with this

stepper example

Test