Search code examples
iosswift3uisegmentedcontrol

How to use segmented control as an add minus feature


I am trying to create an app where I want a user to be a able to increase and decrease a number using a segmented controller. I have two problems.

  1. One side is always selected, how can I make it so it will only be selected when the user is touching it?

The Plus side is selected

  1. How do I register if the same side is tapped? I have seen many examples where it shows how to register a tap on the other segment.

Solution

  • You are using the wrong control for this. There is a UIStepper which will do what you want.

    https://developer.apple.com/documentation/uikit/uistepper?changes=latest_minor