How to use Stepper UI control in IOS

October 4, 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 from the Object Library

Place Label ControlĀ  to show the stepper value

Next you can create the Outlet for Stepper and Label

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