当我试图将另一个VStack放到ZStack中时,我得到了奇怪的填充。如何去除它?
struct ContentView: View {
var body: some View {
VStack{
VStack{
Text("1")
}
.frame(width: 200, height: 50)
.background(Color.init(.green))
ZStack{
VStack{
Text("2")
}
.frame(width: 210, height: 50)
.background(Color.init(.blue))
VStack{
Text("3")
}
.frame(width: 200, height: 50)
.background(Color.init(.green))
}
VStack{
Text("4")
}
.frame(width: 200, height: 50)
.background(Color.init(.green))
}
}
}
如果我用Text("2")注释VStack,padding会消失。
在这里,它是...
var body: some View {
VStack(spacing: 0) { // << here !!
你提供了不同的宽度在
VStack{
Text("2")
}
.frame(width: 210, height: 50)
.background(Color.init(.blue))
宽度是 210 和其他元素的宽度为 200 提供相同宽度的填充物将被移除。