21.7 Frames and the Geometry Reader
Frames can also be implemented so that they are sized relative to the size of the container within which the corresponding view is embedded. This is achieved by wrapping the view in a GeometryReader and using the reader to identify the container dimensions. These dimensions can then be used to calculate the frame size. The following example uses a frame to set the dimensions of two Text views relative to the size of the containing VStack:
GeometryReader { geometry in
VStack {
Text("Hello World, how are you?")
.font(.largeTitle)
.frame(width: geometry.size.width / 2,
height: (geometry.size.height / 4) * 3)
...