We’ve arrived at day 93 of the 100 Days of SwiftUI! After finishing Flashzilla and starting the final technique project, we’re looking into positioning views and some advanced usage of GeometryReader
. Let’s dive in!
Absolute positioning for SwiftUI views
SwiftUI gives us two ways of positioning views: absolute positions using position()
, and relative positions using offset()
. They might seem similar, but once you understand how SwiftUI places views inside frames the underlying differences between position()
and offset()
become clearer.
Choosing the right positioning ensures that our views are positioned correctly and our app looks its best.
Understanding frames and coordinates inside GeometryReader
We’ve used the GeometryReader
many times before now. The most important thing to keep in mind is the way the GeometryReader
works:
The parent proposes a size for the child, the child uses that to determine its own size, and parent uses that to position the child appropriately.
Keeping this in mind, GeometryReader
allows us to use its size and coordinates to determine a child view’s layout.
Wrap up
That’s it for day 93! We’re into the final week of the course tomorrow and we start it off by wrapping up this project. Time to recharge!
100 Days of SwiftUI – Day 93