iOS UIStepper With Examples

In this tutorial, we’ll be discussing and implementing the UIStepper Control in our iOS Application.


UIStepper is a basic UI control element that is used to increment/decrement values. This UI element is commonly used in shopping cart applications to increase or decrease the quantity.

A UIStepper consists of the following important properties.

  • minimum/maximum values – The upper and lower limits of the UIStepper.
  • stepValue – The increment/decrement value. By default, this is 1. A stepValue property is a Double.
  • autorepeat – If this is true, pressing and holding the button would keep incrementing/decrementing the value. Otherwise pressing would increment/decrement only once. By default this is true.
  • continuous – If this is true, the value would be changed immediately as soon as the button is touched. By default it is true.
  • wrap – When this is true, the UIStepper increments/decrements in cycles. That means that once the minimum value is reached, decrementing further would start from the maximum value and vice-versa.
    When this is false once the UIStepper reaches the min/max you cannot click any further. The buttons get disabled as well.

Some more important properties and functions –

  • tintColor – Used to set the color of the key elements of the UIStepper.
  • setIncrementImage(image:, for:) – Sets the image for the increment button for the state assigned. A UIImage instance is passed. The states can be normal, focused, highlighted.
  • setDecrementImage(image:, for:) – Sets the same for the decrement button.
  • setDividerImage() – Used to set the divider image.

Irrespective of the image color, the image that gets displayed in the UIStepper would have the tint color which is by default light blue.The image size must be under 25X25 to fit nicely inside the UIStepper.

We’ll look at the click listener functions in the XCode project that we implement next.


Create a new XCode project. In your Main.storyboard, drag a UIStepper and a Label on the ViewController as shown below:


  1. Set the constraints on the UIStepper to center horizontal and vertical in the parent. Set the Label to center horizontal and add a vertical spacing to it from the UIStepper. Link these Outlets to the ViewController.swift
  2. In the right pane the attributes can be changed. Or they can be done programmatically.

The ViewController.swift code is given below:

Using the addTarget method we set the function to be called when the value of the UIStepper is changed by setting the event to valueChanged.

In the stepperValueChanged function, we get the current step value using sender.value and set it on the Label.

sender.value is of the type Double, so we’ve converted it into a String.

The output when the application is run on a simulator is:

ios uistepper basic output 1

The value is displayed in Decimal(Double). When the UIStepper button is pressed, it keeps incrementing and goes over the maximum value which was 20.

autorepeat and wrap. No continuous.

ios uistepper basic output 2

No Autorepeat, No wrap, No continuous

ios ui stepper no autorepeat no wrap

As you can see the + button is disabled.

Adding Tint Color and Step Value

In order to display an Integer value, we need to convert the double to Int first and then to a String.

To add a Tint color and step value, set the following inside the viewDidLoad method.

The output of the application in action is :

ios uistepper tint color and step value

Let’s create another UIStepper in which we’ll set custom images.

Creating UIStepper Programmatically

In the following ViewController.swift, we’ve updated the viewDidLoad method to add a custom UIStepper with image assets set on the left, right and divider elements. You can find the images in the project source code attached at the end of this tutorial.

We’ve added the AutoLayout constraints programmatically as well:

The output of the application in action is given below:

ios uistepper final output

As you can see the tintColor gets applied on the images as well.

This brings an end to this tutorial. You can download the project from the link below.

By admin

Leave a Reply

%d bloggers like this: