Custom Toggle Styling in SwiftUI

How to create custom SwiftUI toggles for your iOS Apps

Alessandro Manilii
5 min readApr 15, 2024

In a previous article, I demonstrated how important it is to customize the button component in SwiftUI using a style instead of creating a button from scratch. This approach becomes increasingly useful as the complexity of the component grows.

One of the most common UI element is the toggle , previously know as switch. We can use toggles for an incredible number of user cases… could be simple on/off buttons, could be fields to select/unselect in a user panel, etc…

In this article, I will show you how to create custom styles to modify the toggle component in SwiftUI as you see fit.

As usually, you can find all the code and the downloadable PDF version of this article in my Patreon page. Subscribe and support me if you like.

The Toggle

A toggle is a pretti basic and useful UI element. It is made by two components:

  • a label with a text and or an icon
  • a button with an on/off state

It is bound to a variable describing its state:

--

--

Alessandro Manilii

I’m an Italian professional iOS Developer, iOS Tech Lead at Wakala — Join Medium from the following link: https://medium.com/@alessandromanilii/membership