Spacer
Create spaces between components.
Spacer
Create spaces between components.
0
0
Checkbox to mark video as read
Mark as read

Spacer() is a UI component that "pushes" the resot of the components in order to create a space between them. It can be used horizontally or vertically.

Let's check an example where we show two squares on each side of the screen.

HStack {
    Rectangle()
        .fill(.red)
        .frame(width: 100, height: 100)

    Spacer()

    Rectangle()
        .fill(.blue)
        .frame(width: 100, height: 100)
}


We can use multiple Spacer() and they will take the available space proportionally.

HStack {
	Spacer()

    Rectangle()
        .fill(.red)
        .frame(width: 100, height: 100)

    Spacer()

    Rectangle()
        .fill(.blue)
        .frame(width: 100, height: 100)

    Spacer()
}


course

Quiz Time!

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy