如何删除 ZStack SwiftUI 中的填充
How to remove padding in the ZStack SwiftUI
我在尝试将另一个 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,填充将消失。
您在
中提供了不同的宽度
VStack{
Text("2")
}
.frame(width: 210, height: 50)
.background(Color.init(.blue))
宽度为210,其他元素宽度为200
提供填充将移除的相同宽度。
在这里
var body: some View {
VStack(spacing: 0) { // << here !!
我在尝试将另一个 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,填充将消失。
您在
中提供了不同的宽度VStack{
Text("2")
}
.frame(width: 210, height: 50)
.background(Color.init(.blue))
宽度为210,其他元素宽度为200 提供填充将移除的相同宽度。
在这里
var body: some View {
VStack(spacing: 0) { // << here !!