Complete the code to create a GeometryReader that fills the available space.
GeometryReader { geometry in
Color.blue
.frame(width: geometry.size.[1], height: geometry.size.height)
}The geometry.size.width gives the width of the available space inside GeometryReader.
Complete the code to center a Text view inside GeometryReader using its size.
GeometryReader { geometry in
Text("Hello")
.position(x: geometry.size.width / [1], y: geometry.size.height / 2)
}Dividing width by 2 centers the Text horizontally inside GeometryReader.
Fix the error in the code to make the Rectangle adapt to half the GeometryReader's width.
GeometryReader { geometry in
Rectangle()
.frame(width: geometry.size.[1] / 2, height: 100)
}The width property of geometry.size gives the full width; dividing it by 2 sets half width.
Fill both blanks to create a VStack that adapts its padding based on GeometryReader's width.
GeometryReader { geometry in
VStack {
Text("Adaptive Padding")
}
.padding(geometry.size.[1] / [2])
}Padding is set to half the width by dividing geometry.size.width by 2.
Fill all three blanks to create a Text view that changes font size and position based on GeometryReader's size.
GeometryReader { geometry in
Text("Responsive Text")
.font(.system(size: geometry.size.[1] / [2]))
.position(x: geometry.size.width / [3], y: geometry.size.height / 2)
}The font size is based on half the width (width / 2), and the x position is one third of the width (width / 3), centering vertically.