# Layout and geometry: Wrap up

Paul Hudson    @twostraws

I hope this smaller technique project proved a welcome break after our long app projects, but I hope even more that you’re really starting to have a good mental model of how SwiftUI’s layout system works. That three step layout system might sound simple, but it takes time to fully understand the ramifications it has.

As for `GeometryReader`, it’s one of those things you can get by perfectly fine without even thinking about, and that’s fine. But when you want to add a little pizazz to your designs – when you want to really bring something to life as the user interacts with it – `GeometryReader` is a fast and flexible fix that offers a huge amount of power in only a handful of lines of code.

## Review what you learned

Anyone can sit through a tutorial, but it takes actual work to remember what was taught. It’s my job to make sure you take as much from these tutorials as possible, so I’ve prepared a short review to help you check your learning.

## Challenge

One of the best ways to learn is to write your own code as often as possible, so here are three challenges for you to complete to experiment with your knowledge of `GeometryReader`.

First, put your `ContentView` back to the spinning color rows example we had:

``````struct ContentView: View {
let colors: [Color] = [.red, .green, .blue, .orange, .pink, .purple, .yellow]

var body: some View {
ScrollView(.vertical) {
ForEach(0..<50) { index in
Text("Row #\(index)")
.font(.title)
.frame(maxWidth: .infinity)
.background(colors[index % 7])
.rotation3DEffect(.degrees(geo.frame(in: .global).minY - fullView.size.height / 2) / 5, axis: (x: 0, y: 1, z: 0))
}
.frame(height: 40)
}
}
}
}
}``````

With that done:

1. Make views near the top of the scroll view fade out to 0 opacity – I would suggest starting at about 200 points from the top.
2. Make views adjust their scale depending on their vertical position, with views near the bottom being large and views near the top being small. I would suggest going no smaller than 50% of the regular size.
3. For a real challenge make the views change color as you scroll. For the best effect, you should create colors using the `Color(hue:saturation:brightness:)` initializer, feeding in varying values for the hue.

Each of those will require a little trial and error from you to find values that work well. Regardless, you should use `max()` to handle the scaling so that views don’t go smaller than half their size, and use `min()` with the hue so that hue values don’t go beyond 1.0.

Hacking with Swift+ subscribers can get a complete video solution for this checkpoint here: Solution to Layout and Geometry. If you don’t already subscribe, you can start a free trial today.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Sponsor Hacking with Swift and reach the world's largest Swift community!