Image for post
Image for post

Hacking the Button in Sketch

How to make a reusable button symbol with icons.

Aleksandr Pasevin
Nov 20, 2016 · 4 min read

tl;dr: There are working Sketch files for you at the bottom of the article. Go ahead and use it! Make sure you have Sketch v46 or above.

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 center of the button.

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

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

Now this made me wonder if I can do the same but with the icon on the left side. It 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.

Image for post
Image for post
Editing Symbol text via the Overrides section couldn’t shift the icon from its place…

But then it hit me!

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

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

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

Image for post
Image for post
Damn right!

Bonus tips

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

Profit

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

Caution

If you’re working with Zeplin, you might encounter issues with guides. Zeplin doesn’t work well with rotating 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 it! 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!

Design + Sketch

The best collection of articles, tips, tutorials, and…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store