Slices in Sketch allow you to export a defined area on the canvas to single file. A Sketch document can have as many Slices as you want and each will exporting to a different file.
Slices as Layers
Slices in Sketch 3 are now treated as normal layers. The benefits of this new approach are plenty. You can now for example group a Slice together with the content that its supposed to export, and when you move the group around, the Slice moves with it.
If you temporarily don’t want to be bothered by Slices in your canvas, you can turn them off at the bottom of the layer list by clicking the little knife icon.
You can add a Slice by going to Insert › Slice in the toolbar and then click and drag anywhere in the Canvas to define the area. When inside the Slice tool, you can also just click on a layer and Sketch will create a new Slice exactly around that layer.
You can give each of your Slices their own name, and this is the name that will be used when you export your Slice.
A neat trick is that you if you include a slash (/) it will place that Slice in a new folder. For example, if you named your Slice ‘foo/bar.png’, it would first create a folder named ‘foo’ and then create a image named ‘bar.png’ in there.
New in Sketch 3 is that you can export multiple images out of a single Slice. If you’re doing iOS designs for example you will often want to export a single and double-resolution for each icon. With Slices in Sketch, this is easy. Just click the + icon in the inspector to add a second size.
Each size can have its own custom Scale, Format and Suffix. The suffix is required because normally the filename is derived from the name of the Slice, but with two exportable sizes, you need to suffix one of them. By default the second size you add be a 2x size with a [email protected] suffix according to iOS’s naming convention.
You are however not restricted to just 2x export; you can export to any resolution or size with any suffix you want. If you design at double resolution already for example, you can give your 1x size a [email protected] suffix and have your second size be at 0.5x.
Group Contents Only
Sketch 2 had a way to export only certain layers for each Slice. And while this concept was easy to understand, it quickly turned into a messy process if you wanted to change things or started replacing elements in your design.
Instead in Sketch 3, each Slice now just has one checkbox; Export Group Contents Only. When this is checked instead of exporting everything on the canvas, the Slice will now only export the layers inside its own group, discarding any overlapping layers outside it, or any background layer behind it.
The last option available on every slice is Trim. With this turned on every Slice that will be exported will have transparent pixels trimmed away from its edges.
For example: You defined a slice somewhere in your document of 30 by 40 pixels, but it contains a single oval which is just 15x15 pixels. Instead of resizing your slice to fit exactly around this oval you turn on Trim, and Sketch will trim away the transparent pixels in your 30x40 slice until a small 15x15 image is left.