Create Adaptive Buttons Using Combined Shapes In Sketch

Travis Folck
Dec 17, 2018 · 7 min read
The problem we’re solving, shapes don’t respond to override text.

Introducing the Combined Shape Method

Using the power of combined shapes, this tutorial will show you how to create a button and button groups that adapt to the override text length. These buttons can be used on their own and can be nested in other symbols.

This tutorial shows how to create adaptable buttons that can be nested into symbols.

This method can be used to create multiple button style combinations, we’ll be focusing on creating a solid button and text-only button for this tutorial.

This method can also be used to create any button style combinations.

How this method works

This method combines everything into a single shape. If you’re familiar with shapes, you’ll quickly realize the drawbacks to this method. Some layers will be subtracted from others, such as the text. Anything behind the button appears where the text is. Also, only one color can be applied to the entire shape.

Use this technique if:

  • Only one color is needed for all of the buttons
  • The solid button text color and the parent’s surface color is the same

Don’t use this technique if:

  • The solid button needs a drop shadow; if one is applied here, it will appear behind the text.
  • Different colors are needed for the buttons or button outline

Enough already, show me how!

This tutorial assumes you have some experience with creating combined shapes in Sketch, but is hopefully written so anyone can follow.

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.

  • Width: 140
  • Height: 36

Add the surface layer

Since we don’t know the maximum length of the button, we’re going to give the surface layer a ridiculous length. It will be revealed as the override text length increases. This is also the right side of the button, so the right corners will be rounded.

  • Width: 500
  • Height: 36
  • X: -360
  • Radius: 0;4;4;0 (for the right-side rounded corners)
  • Color: 6200EE (or any color)

Add text for the solid button

To make the button right aligned, we will pin it to the right of the artboard. The text override will push everything to the left, as it grows.

  • Pin to edge: right
  • Fixed size: Height
  • Font: Roboto
  • Size:14
  • Weight: Regular
  • Line: 36
  • Alignment: Right
  • Text Transform: Upper case (optional)
  • Text: OK

Combine surface and text layers into a shape

  • Rename the layer to Surface Mask
  • Rename the layer to Button Color . This will be the override menu label for changing the color of the button.

Add the surface mask layer

We need to ‘mask’ the surface layer so it only appears as the text layer grows in length. The mask layer needs to be the length of the Surface layer, minus the text layer width (19px) and spacing from the text to the end of the art board(16px).

  • Width: 465
  • Height: 36
  • X: -360
  • Combine Method: Subtract

Test your progress

Add the symbol to the page and add text in the Solid Button Text override. The override text should move the Surface Mask layer, revealing more of the Surface Mask color.

It should look like the button is adapting to the text length.

Complete the solid button

We need to ‘cut out’ part of the Surface Mask . A fixed-shape rectangle with two rounded corners will be used. Like the Surface Mask, it will move with the override text.

  • X: 89 (Note: it should not overlap the surface layer.
  • Width: 16
  • Height: 36
  • Radius: 4;0;0;4
  • Fixed size: horizontal

Test your progress

Like before, test your progress by adding the symbol to the page and entering text in the override menu. The Left Cutout layer should move as override text is entered. It should also not change shape as the symbol is resized.

Add text-only button

Whew, almost done! Complete the button group by adding a text-only button.

  • Fixed size: Height
  • Font: Roboto
  • Size:14
  • Weight: Regular
  • Line: 36
  • Alignment: Right
  • Text Transform: Upper case (optional)
  • Text: Cancel

Done!

You should now have a symbol with solid and text-only buttons that can be used on their own, or nested in other sytems and still respond to the override text.

What can you do with this method?

As mentioned earlier, this method can be used to create so many variations and combinations of adaptable text. Let me know what you create by using this technique!

This method can also be used to create any button style combinations.

Design + Sketch

The best collection of articles, tips, tutorials, and stories on designing and prototyping with Sketch and beyond

Travis Folck

Written by

I love technology and design. I find great satisfaction when they come together to create a great experience.

Design + Sketch

The best collection of articles, tips, tutorials, and stories on designing and prototyping with Sketch and beyond