Documentation

Unity Spark

Open Unity Spark

Unity Spark

Align elements and make your UI fit every screen

Line up and space UI elements, group and fit them automatically, set anchors, and preview your UI on different screen shapes in Unity Spark.
Read time 3 minutesLast updated 3 hours ago

Align and space elements so your screens are tidy, then set anchors so each element stays where it belongs when the screen size changes. For more information about anchors, refer to Anchors.

Align and space elements

The toolbar at the top of the UI Editor has tools to snap, align, and distribute elements:
  • Snap (magnet icon) snaps elements to alignment guides as you drag. Hold Ctrl (macOS: Cmd) while dragging to temporarily enable or disable snapping.
  • Align aligns the left edges, centers, right edges, tops, or bottoms of two or more selected elements.
  • Distribute spaces three or more selected elements evenly, horizontally or vertically.
For the full list of top toolbar tools, refer to Top toolbar.

Set anchors

To set anchors:
  1. Select one or more elements.
  2. In the Inspector window, open Anchor presets next to Anchor.
  3. Select a preset. The following presets suit common layouts:
    • For a score in the top-left corner, anchor the score to the top-left.
    • For a pause button in the top-right corner, anchor the pause button to the top-right.
    • For a full-screen background, stretch in both directions.
To also set the pivot, hold Shift when you select a preset. To also move the element to that spot, hold Alt (macOS: Option).
To set each element's anchor automatically from where you place, move, or resize it, enable Auto-anchor in the UI Editor's top toolbar.

Group and fit elements

To arrange elements automatically, add one of the following components to their parent element with Add Component in the Inspector window.

Component

Description

HorizontalLayoutGroupArranges the child elements in a row, with Spacing and Padding.
VerticalLayoutGroupArranges the child elements in a column, with Spacing and Padding.
GridLayoutGroupArranges the child elements in a grid of cells of the same size, such as an inventory.
ContentSizeFitterResizes the element to fit its content, for example, to grow a list as you add items.
AspectRatioFitterKeeps the element's proportions when its size changes.
LayoutElementSets an element's minimum, preferred, or flexible size inside a layout group, or leaves it out of the layout.
To change several elements together, use the following components.

Component

Description

CanvasGroupFades, hides, or disables an element and all the elements inside it, for example, to fade in a menu.
MaskShows the child elements only inside the shape of this element's graphic.
Outline and ShadowAdds an outline or a drop shadow to text or an image.

Preview different screen shapes

To check different screen shapes:
  1. Select the aspect-ratio menu in the Scene view's toolbar or the UI Editor's top toolbar. Both menus share the same setting.
  2. Select Free, 16:9, 16:10, 3:2, 4:3, 1:1, or 9:16 (phone portrait), or add your own.
To view how your UI sits over the game, use Camera display in the UI Editor's top toolbar to show one of your scene's cameras behind the UI.

Additional resources