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.
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.
But then it hit me!
What if we can trick Sketch? What if we rotate the “Label” group -180°, what will happen then?
Now the behaviour is what I was looking for, the only thing we need to do is flip the text -180°, right?
- 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.
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!
You can find my Sketch files here. You can use them as a basis for your own buttons.
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!