Borders

It seems a little odd to write a post about borders, since every post so far has already used them without calling them out. In all of the examples I’ve added borders to views and used the result in the previews, rather than drawing them in by hand. But I haven’t actually shown the code […]

Geometry Reader

For most layout needs we can combine stacks and flexible frames, allowing us to make views and controls put together from fixed size primitives views upwards. For more complex layout needs, another option is to use GeometryReader. This is a construct that acts like an infinite frame, proposing the size of its parent to its […]

Secondary Views in Practice

A secondary view, be it background or overlay, can be any view. We know from flexible frames that we can create views of fixed sizes, sizes based on their children, or sizes based on their parent. And we saw above that the proposed size of a secondary view is the fixed size of a parent. […]

Padding

In views have fixed sizes, we introduced the idea that all views in SwiftUI are fixed in size, for example a Text view has the size required to render the string provided: Creates a view with the exact bounds necessary: We also showed that the .frame modifier actually creates a new view with the dimensions […]

Exploding Stacks

A common layout desire is to place views in the corner of a larger view, or of the device. This is particularly interesting because it’s more instructive to visit the methods that don’t work and explain why, before showing the best way to do it. Our desired result is as follows: We’ll concentrate first on […]