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
- GeometryReader Essentials
- Custom Alignment Guides
- The Layout Protocol
- Building a Flow Layout