I know that GeometryReader
takes all spaces available
but Why they anchored theirs contents(child views) to topLeading corner?
This is my code
struct ContentView: View {
var body: some View {
VStack {
GeometryReader { proxy in
Text("First Stack")
.foregroundColor(.black)
.font(.largeTitle)
}
.background(Color.red.opacity(0.4))
Text("Second Stack").background(Color.blue)
}
.background(Color.yellow.opacity(0.5))
}
}
and result like this
Text
has own size, but why it anchored or aligned topLeading
Is this default behavior of GeometryReader
?
I try to make it center in GeometryReader
like this
struct ContentView: View {
var body: some View {
VStack {
GeometryReader { proxy in
Text("First Stack")
.position(x: proxy.frame(in: .local).midX, y: proxy.frame(in: .local).midY)
.foregroundColor(.black)
.font(.largeTitle)
}
.background(Color.red.opacity(0.4))
Text("Second Stack").background(Color.blue)
}
.background(Color.yellow.opacity(0.5))
}
}
Is it right solution for center Text
in GeometryReader
?