我有以下代码:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("ContentView Header 1")
.border(Color.green, width: 2)
Text("ContentView Header 2")
.border(Color.green, width: 2)
Image(systemName: "arrow.up")
.border(Color.green, width: 2)
Text("ContentView Footer 1")
.border(Color.green, width: 2)
}
}
}
结果如下:
为什么图像周围有间距,但文字周围没有间距?当我为VStack
明确设置间距时,它消失了。
答案 0 :(得分:2)
public struct VStack<Content> : View where Content : View { /// Creates an instance with the given `spacing` and Y axis `alignment`. /// /// - Parameters: /// - alignment: the guide that will have the same horizontal screen /// coordinate for all children. /// - spacing: the distance between adjacent children, or nil if the /// stack should choose a default distance for each pair of children.
最后一行-“堆栈应为每对孩子选择默认距离”