Sketch Hacks: Make a Resizable Button with Icon and Label

With Auto Layout and a bit of hacking, this true holy grail* of completely basic elements can be achieved.

Nando Rossi
Design + Sketch
3 min readJan 30, 2018

--

Yeah I know Aleksander. Thanks for the inspiration ;)

Update: this hack is outdated; check out my newest article with a plugin-free solution to this problem.

It’s been lovely to watch Sketch evolve into the robust playform it is today, however many of our project files have become painfully outdated. So we decided 2018 is time for some housekeeping: time to recreate the files.

We did all the fancy new stuff: atomic design, nested symbols with overrides, naming conventions, etc. All was going great, until I hit one giant bump on the road: the impossible button-with-an-icon-and-a-label.

Looks easy, but try doing this with just one symbol…

I tried everything I could think of—grouped layers, nested symbols, a myriad of combinations of Sketch’s native resizing features, to no avail. I tried every hack I found on the web, no dice (outdated or just didn’t work). I tried and gave up for weeks. That’s when I decided to try Anima’s Auto Layout, and finally succeeded.

How I Did It

Create a symbol, I’ll name mine “button.” Add an icon there, and a text label right next to it. Select both layers and group them.

Now select that group and turn it into a symbol (I named mine “Label”):

Now comes the magic stuff:

On the “Label” symbol, select that group you created. On Anima’s Auto Layout, select “Pin To Center Horizontally”

Finally, on the main “Button” symbol, set the “Label” symbol “Fix Width:”

And that will be it! Your button should now resize with no problems…

… including very, very long labels!

You can download the sketch file I created here if that helps. Big thanks to UX Power Tools for all the hacking inspiration. :)

* not truly a holy grail at all

--

--