0Pricing
SwiftUI Academy · Lesson

The Layout Protocol

Implement sizeThatFits and placeSubviews.

Beyond Stacks

When stacks and grids are not enough, the Layout protocol lets you write your own container that positions children exactly how you want. 🧩

Two Required Methods

Conform to Layout by implementing sizeThatFits and placeSubviews, the two steps every custom layout needs.

struct MyLayout: Layout {
    func sizeThatFits(...) -> CGSize { ... }
    func placeSubviews(...) { ... }
}

All lessons in this course

  1. GeometryReader Essentials
  2. Custom Alignment Guides
  3. The Layout Protocol
  4. Building a Flow Layout
← Back to SwiftUI Academy