Create Advanced Adaptive Buttons Using Layers In Sketch

This is the second method for creating adaptive buttons in Sketch. Be sure to check out the first method: Create Adaptive Buttons Using Combined Shapes In Sketch.

This method allows you to create adaptive buttons with a drop shadow, ability to change the button surface color and text color; even when nested in other symbols.

This method allows adaptive solid buttons with optional drop shadow
⬇︎ Download Sketch File

As mentioned in the Combined Shapes article, symbol dimensions do not respond to text length. Thus, solid button dimensions do not adapt to their override text length. Let’s fix that.

Introducing the Layer Method

This article can be used to create a combination of multiple button styles, we’ll be focusing on creating a button row. For maximum flexibility, we’ll create two symbols: one with a drop shadow and one without.

How this method works

This method uses some techniques from the previous article, but uses layers instead, allowing for the ability to apply different colors to the button surface and labels.

This method uses a layer to hide the solid button’s surface color. The layer is the same color as the surface that the buttons resize on.

Step-by-step instructions

This tutorial looks rather long, but it should go quick. It is assumed that you have some experience with Sketch layers and creating combined shapes. If you find this method too difficult, please check my other post for a simpler method for creating adaptive buttons.

Tip: To make the button respond to override text length, we’ll be using the method described in: Create an Adaptive Sketch Symbol for Material Design’s Outlined Text Field.

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.

  • Symbol name: Button Row — Solid and Text/Left Aligned — No Shadow
  • 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 left side of the button, so the left corners will be rounded.

Add a new rectangle shape:

  • Layer name: Solid Button Color
  • Width: 500
  • Height: 36
  • Radius: 4;0;0;4 (for the left-side rounded corners)
  • Color: 2E73E7 (or any color)
Tip: If you create a layer style, you’ll be able to change the button color when it’s nested in a symbol.

Add text for the solid button

The text override will push everything to the right, as it grows. Unlike combined shape method, we can apply styles to the solid button text.

Add a text layer above the surface layer:

  • Layer name: Solid Button Text (this will be the name in the override)
  • Pin to edge: left
  • Fixed size: Height
  • Font: Roboto
  • Size:14
  • Weight: Medium
  • Color: White, 87% opacity
  • Line: 36
  • Alignment: Left
  • Text Transform: Upper case (optional)
  • Text: OK
Tip: The override text will push neighboring layers, revealing the surface color as the text lentgh grows. Line height is used to increase the text height. Check out this post for more information on adaptable text.

Add the surface overlay layer

We need to hide the surface layer so that it only appears as the button’s override text grows. This layer will need to be the same color as the layer the buttons will on top of. The layer will need start immediately after the text layer and cover up the rest of the Solid Button Color layer.

Add a rectangle layer:

  • Name: Solid Button Overlay
  • X: 42 (immediately after the text layer)
  • Width: 458
  • Height: 36
Tip: To maximum flexibility, consider applying a layer style to this layer. This will allow you to change the color to match the the color behind the button.

Complete the solid button

We need to cut out the Solid Button Overlay We’ll create a new fixed sized layer with two rounded corners and then subtract it from the Solid Button Overlay layer.

Above Solid Button Overlay, add a new rectangle layer:

  • Layer name: Cutout
  • X: 42 (Note: it should not overlap the surface layer.
  • Width: 9
  • Height: 36
  • Radius: 0;4;4;0
  • Fixed size: horizontal

Combine Shapes

Using the Subtract method, combine the Cutout layer and Solid Button Overlay layer.

  • Combined shape layer name: Solid Button Overlay
  • Fixed size: horizontal

Test your progress

Add your symbol the the page and type in the override text field. The text should push the Surface Button Overlay layer, revealing the Solid Button Color layer.

If you used a layer style for the color, the button surface color can also be changed in the Solid Button Color layer.

Add the text button

Complete the button group by adding a text-only button to the symbol.

  • Layer name: Text Button Text
  • Fixed size: Height
  • Font: Roboto
  • Size:14
  • Weight: Medium
  • Color: Black, 87% opacity
  • Line: 36
  • Alignment: Left
  • Text Transform: Upper case (optional)
  • Text: Cancel

Add the mask

You may have noticed the Solid Button Overlay layer extending beyond the art board, let’s fix that now.

Add a new rectangle layer as the last layer and give it the dimensions of the art board:

  • Layer name: Button Row Mask
  • Width: 140
  • Height: 36
  • Pin: all sides

Test your progress

Try out your button row symbol. The solid button should adapt the length of the override text.


If you have been following these steps, you should have a fully functioning button row with a solid button (without a shadow) and a text-only button. You can use the symbol by itself and add it to other symbols.

If you only need adaptable buttons without a drop shadow, you can stop here. But why stop here? Let’s create a version with a drop shadow.


About adding a drop shadow

To create the drop shadow effect, we will create the shadow in two parts. One above and one below the Solid Button Color layer. This will allow users to still be able to change the button color.

We’ll duplicate the button symbol we just created and slightly modify it.

Copy the button row symbol

Copy the Button Row — Solid and Text/Left Aligned — No Shadow symbol and rename it to:

Button Row — Solid and Text/Left Aligned — With Shadow

Resize mask layer

To show the shadow, the Button Row Mask will need to be resized. Otherwise, it will cut off the shadow. Making the mask larger than the art board will not impact the symbol size.

Resize and reposition Button Row Mask:

  • Width: 142
  • Height: 42
  • X: -2
  • Y: -3

Add button shadow

Below the Solid Button Color layer, create a shape with the same dimensions as the Solid Button Color layer. We’ll fill color opacity 0%, in case someone tries to use an opaque color fill for the button color.

  • Layer name: Solid Button Shadow
  • Width: 500
  • Height: 36
  • Radius: 4;0;0;4
  • Fix size: Horizontal
  • Fill: Any color; 0% opacity
  • Shadow 1: #000000 12% opacity; blur: 2
  • Shadow 2: #000000 24% opacity; blur: 2

Mask the shadow

Just like the Solid Button Color layer, we need to hide the shadow for it to be revealed later.

Expand the Solid Button Overlay layer, select the Solid Button Overlay layer within and change Y coordinate and height to:

  • Y: -2
  • Height: 41

Add the right-side shadow

The right side of the button doesn’t have a shadow. Let’s fix that. We want the shadow to be transparent in order to see the button’s color. It needs to be placed after the text layer so that it moves as the override text length increases.

Above Solid Button Text layer, add a new rectangle:

  • Layer name: Solid Button Right Side
  • Width: 16
  • Height: 36
  • X: 35
  • Radius: 0;4;4;0
  • Fix size: width
  • Fills: Any color; 0% opacity
  • Shadow 1: #000000 12% opacity; blur: 6
  • Shadow 2: #000000 24% opacity; blur: 2

Mask the right-side shadow

The shadow for the right side of the button is overlapping the primary shadow. Let’s mask the shadow from preventing this.

Above Solid Button Text, create a new rectangle layer:

  • Layer name: Solid Button Right Side Shadow Mask
  • Width: 11
  • Height: 41
  • X: 42
  • Y: -2
  • Fix size: horizontal

Done!

You should now have a fully functioning adaptive solid and text-only buttons with a drop shadow for the solid button and the abiltiy to change the button color. Use this symbol by itself or nest it other symbols!

This method can be used anywhere you need to make adaptive solid-color shapes. I’d love to hear how you’ve used this method to solve some of your challenges in Sketch. Drop a comment below!

⬇︎ Download Sketch File