A button, with an icon and label, both floating in the center. Simple enough, but only with the right hacks.

A few months ago, I wrote this article detailing a hack to solve a problem I was having while setting up a design system: creating a button with an icon and label, which can be stretched while keeping both icon and label centered. I tried to coax Sketch’s resizing into doing this but failed.

Finally, using the Anima plug-in I was able to do it, however it broke rather quickly, exposing the big problem with relying on plug-ins for your core file production: updates break things.

A native solution

I got tons of feedback on that article, mostly from people frustrated by the lack of a native solution. Only one commenter, however, offered a solution to this puzzle. This article is based on Caio’s hack, and it works quite well. Note: the following steps assume an icon on the left. If you want the icon on the right, simply skip steps 2 & 3 (180˚ rotations).

1. Create the “Button” symbol, inverted at first: add an icon (on the right) and text label (on the left).

Make sure text label alignment is Auto and Centered.

2. Group icon and label. Rotate the label group 180° (it will be upside down)

4. Set resizing and alignment to each layer and group exactly as shown:

5. Turn the Group into a symbol (we’re naming ours Label-with-icon). Keep the group folder in there (we renamed ours Alignment Container)

6. Back to the “Button” symbol, stretch the “Label-with-icon” so its width is the same as the button.

And that’s it!

This symbol can be stretched, the text made whatever size it needs to be and the label will float in the center.

Conclusion

From the sheer volume of responses my previous article received, I sure hope Sketch is listening to the community and focusing on streamlining important workflows like these. Until then, using hacks like these is more reliable long-term than relying on plug-ins.

Thanks for reading! If this was useful to you, please give it some applause! 😊