I\'m using a \"RectGetter\" to get the CGRect
of a View
.
Like this:
Text(\"Hello\")
.background(RectGetter(rect: self.
I use such function. Works since Xcode 11.1
func rectReader(_ binding: Binding<CGRect>) -> some View {
return GeometryReader { (geometry) -> AnyView in
let rect = geometry.frame(in: .global)
DispatchQueue.main.async {
binding.wrappedValue = rect
}
return AnyView(Rectangle().fill(Color.clear))
}
}
Usage the same
Text("Test").background(rectReader($rect))