VStack图像周围的间距,但文本周围不

时间:2020-01-10 07:12:17

标签: swiftui

我有以下代码:

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)
        }
    }
}

结果如下:

vertical stack showing two texts, an image and another text, with space around the image

为什么图像周围有间距,但文字周围没有间距?当我为VStack明确设置间距时,它消失了。

1 个答案:

答案 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.

最后一行-“堆栈应为每对孩子选择默认距离