Simple Toggle Control in iOS

Leela Prasad
Swift India
Published in
2 min readOct 12, 2019

like Android toggle switch

The toggle switch in iOS looks great, and also supports Haptic feed back, so you might not get a use case to customise it. We can add custom animations, and also can support images or text on thumb control, etc. But this tutorial covers very basic control(Android like toggle) setup.

This how it looks :

Left is iOS & right is Android

Let’s start :

  1. Create an IBDesignable class for the control. IBDesignable attribute helps to setup the UI Element through storyboards.
  2. Define the IBInspectable properties for colors and toggle status, etc that we need to access or set the values. IBInspectable attributes help to configure the UI Element through storyboards & attribute inspector.
  3. Here I used draw method, to render the control. We can use helper methods also if customisation requires.
  4. And finally on touches ended, I am sending the notification for valueChanged. by toggling the on property on control. We can use the remaining touch event methods, to drag along with the touch, and for more customised state animations.

5. I provided the comments for the code, so you can understand what it does.

— — — — — — — — — *********************** — — — — — — — — —

You can contact / follow me on twitter & linkedIn accounts.

Thanks for reading…

***************************!!!See you!!!****************************

--

--