【发布时间】:2021-04-25 19:34:58
【问题描述】:
如何从另一个视图访问一个视图的大小?
为了获得“Hello world!”文本的高度,我在其上附加了 .background() 或 GeometryReader。目前,我只是使用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 ???")
}
}
}
结果:
我现在想用“Hello world!”的高度替换???。我该怎么做?
【问题讨论】:
标签: ios swift swiftui geometryreader