How to create an ON/OFF switch with Sketch using overlays

I stumbled upon this post where the OP was inquiring about certain symbol states. While Sketch doesn’t support actions like hovers, it’s fairly easy to create certain states like toggles, and even assign additional actions to them via hotspots. Below is an example of what I learned during my trial period using Sketch:

How it’s done

1. Create instances of your symbols

Besides you noticing me using dark background you’ll see I added a solid background color to my symbols, which will play a major role. I’ll get to that.

You’ll also notice the symbol has been converted to an overlay, which is very important.

2. Adjust settings for both Design and Prototype personas

Migrate these settings to all affected instances:

:warning: Things you shouldn’t forget

  • Remember, the symbol is used as an overlay, thus you must add a background to your symbol, else it will not cover the one underlying it. Simply sample the color of the canvas the symbol is attached to.
  • Set the positioning as relative to layer exactly as in the screenshot.
  • Outside interactions must be set to allow all. This is because now multiple overlay effects/actions can be used. If you do not enable this, then clicking one overlay will close the other, etc.

3. Link symbols

Where applicable, add these symbols already as overlays to your prototype on top of the original symbol by applying these settings:

  1. Link the symbol to its other state;
  2. Choose no animation;
  3. Align it relative to layer;
  4. Same as point 3. You might need to nudge the symbol by a few pixels, but ideally it should be in place.

If you’ve followed these instructions carefully you should get the same outcome. This method applies also to creating toggles of all kinds, from simple switches to checklists, et al.



Thanks for sharing this @Kilobyte9335 ! I’m going to give this a try and I’m sure this will be useful for others as well.

1 Like

Hey Patrik! Thanks so much for sharing this tutorial, I liked the technique of setting the loop for switching with Allow all and Close Overlay :ok_hand:

I built two switches following your tutorial’s steps and restricted text overrides (which break the toggle if carried out) Thanks again and here’s the Sketch file for everyone to take a look :raised_hands:
Toggle Switch.sketch (378.2 KB)