Learn how to use Smart Layout in Sketch in this hands-on tutorial with Jeremy Osborn, Academic Director of Aquent Gymnasium.
In this tutorial, you’re going to learn how to use Smart Layout in Sketch. In order to follow along, you can download the lesson file at this URL. Although, there’s also a link to the file in the Resources section for this video.
Smart Layout allows you to control the appearance and behavior of any symbol in Sketch by either applying Horizontal or Vertical Layout to it. You’re going to take a look at Horizontal Layout first, and each pair of these buttons has a specific layout that has already been applied. Now, you’re going to do some typing to force each one to adapt to the content, and when you’re done, I’ll show you how it works.
Go ahead and click on the first button, and in the Override field, type Cd. Then, click the second button, and type Streaming Audio, and you can see here you’ve got some overflowing text. These two buttons are based on the No Layout model which is the default mode for symbol instances.
Now, you’re going to explore how Smart Layout changes this entire game. Go ahead and click on this button and type Cd in the Override field, and the button width shrinks. Click on the second button, type Streaming Audio, and the button width expands which is very convenient.
Now, equally important is how the layout has changed. In both cases, the left edge remain fixed, and here on this button, the right edge contracted, and on this one, it expanded from left to right. Type the word Cd again in this next button, and the layout shrinks but this time from the center and with equal amounts of space on both sides.
Type Streaming Audio, and again equal amounts of space are added to both sides. This is the behavior of Horizontal Centered Layout. Add the same content for these last two buttons, and again the buttons adapt. But this time, the right edge of the button stays fixed, and in the case of the long text, the button layout expands from the right to the left.
Click on the Symbols page, and then click on each of these master symbols in turn. Sure enough, this first one uses No Layout. The second uses Left to Right. The third is Horizontal Centered, and the last is Right to Left.
Now, while we’re here, let’s click on this green master symbol and change the layout from None to Horizontal Centered, just to see what happens. Back on our main page, the layout has not changed. Well, the reason is because of the way Sketch interprets overrides on a symbol instance.
Hover over this double arrow icon which reads Shrink instance to fit content. Click it, and indeed, the button does shrink. Click on the second button, and do the same thing, and you can see here that the button expands. So the best practice here is that if you ever change the layout type of a symbol, be sure to click the Fit Content button to adjust your instance.
Now, you can also define Smart Layout whenever you create a new symbol. So here’s a quick example. press R on your keyboard. Click and drag a rectangle. press T on your keyboard, and type the word label, and drag it to the center.
Click and drag over the whole thing, and press Create Symbol. This dropdown menu is set to No Layout by default, but if you click on that, you’ll see some familiar options. choose Horizontal, click OK, then type Streaming Audio in your Override field, and there you go, working as expected.
Let’s explore a Vertical Layout by clicking on this page, and when you add text into this description field, it overflows by default which is no good. So undo that, and then double-click anywhere inside here to get into the symbol. Now, change the layout from No Layout to Vertical, and specifically, the first option, Top to Bottom.
Why? Because you want the top of your container to stay fixed and the layout to push everything downwards, like so, which it does, and I’m happy. This is cool, but just double-click on the card again to look at the symbol. I want to give you a little warning.
This component is a bit more complicated than our buttons. I did a few things here that we don’t have time to explore. For example, this group of the Album Artist and Description are pinned to the top, left, and right edges and have a fixed size as well. The same is true of a few of the other objects, such as the image.
It’s important to understand the fundamentals of Sketch. These are critical to mastering Smart Layout which is no magic bullet, but it does allow you to do cool things, like resize your components, both horizontally and vertically. Just remember the best practice I mentioned earlier, and if your instances aren’t acting the way you would expect, look for the Fit Content icon, and click it to adjust your layout.