0Pricing
Swift Academy · Lesson

Measuring Subviews

Query subview sizes during layout.

Measurement Drives Layout

Before you can place children, you must measure them. SwiftUI layout is a negotiation: the parent proposes sizes, children respond, and you reconcile the answers.

Asking a Subview Its Size

Each proxy in Subviews answers sizeThatFits(_:) for a given ProposedViewSize. The proxy returns the size that child would take under that proposal.

let size = subview.sizeThatFits(.unspecified)

All lessons in this course

  1. The Layout Protocol Basics
  2. Measuring Subviews
  3. Building a Flow Layout
  4. Layout Cache and Performance
← Back to Swift Academy