Hacking the Button in Sketch

How to make a reusable button symbol with icons.

Update: After Sketch v44 update this hack stopped working. But thanks to Paul Voynov there is a link to a fixed Sketch file here: https://dribbble.com/shots/3684926-Sketch-Button-w-Auto-Aligment-and-Icon

I love Sketch. Coming from the old days of Photoshop, Fireworks it truly has transformed the way I and many other designers work.

I was very excited about the recent updates from Sketch, which included nested symbols, symbol overrides and resizing options. All these features combined together made my life so much easier. And yet there are some cases when I wish it could do more!

In my case I wanted to create a button with a label and an icon. Of course it had to be a Symbol with overrides. I wanted to be able to duplicate this button and override both icon and the label, keeping everything together in the centre of the button.

First I managed to achieve this with the icon on the right side of the label.

Editing Symbol text from the Overrides section
Structure and settings of the symbol. Don’t forget to set text alignment to centre!

Now this made me wonder if I can do the same but with the icon on the left side. Should be easy enough, but not so fast.

When you change the text, the expanding of the label only affects the item on the right side for some reason.

So the results were discouraging and I almost gave up.

Editing Symbol text via Overrides section couldn’t shift the icon from it’s place…

But then it hit me!

What if we can trick Sketch? What if we rotate the “Label” group -180°, what will happen then?

The effect is exactly what I want. One step closer!

Now the behaviour is what I was looking for, the only thing we need to do is flip the text -180°, right?

Damn right!

Bonus tips

  • In case the icon ends up upside down, you can rotate it -180°, same as the text..
  • Replace the icon with a Symbol with fixed proportions. Then you will be able to replace the icons easily via Symbol Override section.
  • The width/height of the button can be adjusted easily.
Structure and settings of the symbol

Profit

Everything stays where it should stay…
… and it’s resizable!

Caution

If you’re working with Zeplin, you might encounter issues with guides. Zeplin doesn’t work well with rotated elements. Check the example file, and export it to Zeplin. Personally for my team it’s not a big issue. You can still see the measurements.

I don’t know how the new updates of Sketch will affect this hack.

I’m not claiming this is the right way to do it. And if there is a better way, please share! I would love this feature to be implemented correctly in Sketch in the future but for now this has served me really well!

Download

You can find my Sketch files here. You can use them as a basis for your own buttons.

The End

This is my first attempt at writing a tutorial, if you can call it so. Please if you have some suggestions, how can I improve it, give me a shout!