0Pricing
SwiftUI Academy · Lesson

GeometryReader Essentials

Measure available space to size content.

GeometryReader Essentials is a free SwiftUI Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Measuring Space

Sometimes a view needs to know how big its slot is. GeometryReader hands you the exact size and position of the space it occupies. 📐

It Is a Container

A GeometryReader is a view whose body is a closure receiving a proxy that describes the available space.

GeometryReader { proxy in
    Text("Hi")
}

The Proxy

That closure parameter is a GeometryProxy. It carries the size, safe-area insets, and frame of the reader.

GeometryReader { proxy in
    let w = proxy.size.width
    Color.blue.frame(width: w)
}

Reading the Size

The most common move is proxy.size, a CGSize giving you the width and height you can fill.

GeometryReader { proxy in
    Text("\(proxy.size.width)")
}

Half the Width

Use the measured width for proportional sizing, like making a bar exactly half of the available width.

GeometryReader { proxy in
    Color.green
        .frame(width: proxy.size.width / 2)
}

It Fills by Default

A GeometryReader greedily takes all the space its parent offers, so its children align to the top-left unless you center them.

Centering Content

Because content pins top-left, wrap it or add a frame with alignment to center children inside the reader.

GeometryReader { proxy in
    Text("Center")
        .frame(width: proxy.size.width,
               height: proxy.size.height)
}

Global Coordinates

Ask for a view position in the window with proxy.frame(in: .global), handy for scroll effects and overlays.

let f = proxy.frame(in: .global)
Text("\(f.minY)")

Safe Area Insets

The proxy also exposes safeAreaInsets, so you can respect notches and home indicators in custom layouts.

let top = proxy.safeAreaInsets.top

Use It Sparingly

A GeometryReader changes layout behavior, so reach for it only when you truly need measurements, not as a default wrapper. ⚠️

Scroll-Driven Effects

Combined with a ScrollView, reading each item frame lets you build parallax and fade effects tied to scroll position.

Quick Check

Recall what the closure hands you.

Recap

You can now read available space with GeometryReader, size views proportionally, and read frames for scroll-aware effects. 🎉

Frequently asked questions

Is the “GeometryReader Essentials” lesson free?

Yes — the full text of “GeometryReader Essentials” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.

What will I learn in “GeometryReader Essentials”?

Measure available space to size content. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SwiftUI Academy?

No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “GeometryReader Essentials” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SwiftUI Academy lesson?

Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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