I want to display a View in the top 1/3 of the screen. In order to do so, I manipulate it as so:
var body: some View {
VStack{
Spacer()
Text("I like chipotle")
Spacer()
Spacer()
}
}
While that works for smaller examples, I wonder if there is a more declarative way to do this so if I for example want to put a view in the top 1/6 of a screen? I think about flex box where you can set the flex value of specific children to make them take up different percentages.
2
Answers
Maybe you mean something like this:
You can add
.ignoresSafeArea(.all)
onGeometryReader
if the entire screen area is neededNo need for any
Spacer
You can directly assign the size to a view relative to its parent using theGeometryReader
:💡 Quick Tip