With the introduction of Smart Layout in Sketch 58, we can finally build adaptable symbols without the hacks, plugins or workarounds.
It is ridiculously easy to create adaptable buttons with Sketch 58 or above.
To see how easy it is, let’s recreate the buttons from my article Create Adaptive Buttons Using Combined Shapes In Sketch but by using the Smart Layout feature, instead.
Create the symbol
Any art board size can be used, we’ll create an art board large enough to hold a solid OK button and text-only Cancel button. Create a new art board and covert to a symbol.
Add the button surface layer
Add a rectangle shape for the solid color button. We give it a fixed width to prevent it from changing if button row symbol is resized. Pin the button to the right side of the art board. For this example, the color
#6200EE was used.
Add the text layer
Add text for the solid color and text button. Pin the text to the right side of the art board, give them a fixed width and make the text right-aligned. Label them
Solid Button Text and
Text Button, respectively .
Modify the art board properties
Now the secret sauce. Click on the art board, in the Inspector Panel, change the layout to
Right to Left. This will make the text and solid button expand when override text is entered.
You now have a button row that will adapt to the text length. This symbol can be used on its own or nested in other symbols. Added bonus: starting with Sketch 58, you can modify the text inline by clicking on it.