How can I access the size of a View from another View?
To get the height of the "Hello world!" text, I attached a .background()
of GeometryReader
to it. For now, I'm just printing the height using let _ = print(proxy.size.height)
.
struct ContentView: View {
var body: some View {
VStack {
Text("Hello world!")
.background(
GeometryReader { proxy in
Color.clear /// placeholder
let _ = print(proxy.size.height) /// 20.333333333333332
}
)
Text("Height of first text is ???")
}
}
}
Result:
I now want to replace ???
with the height of the "Hello world!". How can I do this?