代码是这样的:
struct ContentView: View {
@State var r:CGFloat = 1
var body: some View {
VStack(spacing:0) {
Color.red
.aspectRatio(r, contentMode: .fit)
HStack {
Text("LEFT")
Spacer()
Text("Right")
}
.frame(height: 40)
.background(Color.blue)
}
}
}
#Preview {
ContentView()
}
它简单地画出了这样的东西:
我希望HStack遵循我设置的比率为Color.red
的宽度.
因此,Color.red
的比率可以改变,我希望HStack具有与Color.red
完全相同的宽度
随着r的变化,如何使HStack的宽度与Color.red
视图的宽度匹配?