Stepper

It is a type of UIControl which is used to increase and decrease value. The stepper consists of two buttons. It is associated with a value which gets repeatedly increased or decreased on holding down two of the buttons once at a time. The rate of the change depends on the duration the user presses the control.

We can set the maximum and minimum values for the UIStepper; however, the maximum value will always be greater than the minimum value. If the maximum value lesser than the minimum value, then both these values become equal.

Steps to add Stepper to storyboard

  1. Set up a label, text field, or button whose text is to be changed when changing the stepper value.
  2. Search for the UIStepper in the object library and drag the result to the storyboard.
  3. Create the outlet and action outlet of the stepper into the ViewController.swift file.
  4. Configure the stepper programmatically in the ViewController.swift file.
  5. Set the auto-layout rules for the UIStepper to govern the position and size of the stepper onto the different screen sizes.

Example

In this example, we are using a label and the UIStepper. It is a simple example, in which the text of the label is changed equivalent to the change in the stepper value.

Interface Builder

We have used the label and the UIStepper to create the interface builder shown in the following image.

iOS Stepper

ViewController.swift

Output:

iOS Stepper
Next TopicSwitch




Latest Courses