我正在尝试使用SwiftUI实现以下网格布局,但不确定最佳方法。
我的代码在下面,并没有得到我想要的东西,而且似乎很笨拙,有很多嵌套堆栈
VStack {
VStack {
HStack {
VStack {
Text("Text Here")
Text("336.851")
}
.padding(20)
.background(ColorManager.orange)
.cornerRadius(10)
VStack {
Text("Text Here")
Text("336.851")
}
.padding(20)
.background(ColorManager.red)
.cornerRadius(10)
}
HStack {
VStack {
Text("Text Here")
Text("336.851")
}
.padding(20)
.background(ColorManager.green)
.cornerRadius(10)
VStack {
Text("Text Here")
Text("336.851")
}
.padding(20)
.background(ColorManager.blue)
.cornerRadius(10)
VStack {
Text("Text Here")
Text("336.851")
}
.padding(20)
.background(ColorManager.purpleLight)
.cornerRadius(10)
}
}
}
我的代码给出了以下结果,但我不确定如何将框最大化到屏幕的一半和三分之一。另外,我对嵌套堆栈采用的方法是否正确?