VStack 围绕图像间距,但不围绕文本

2023-11-29

我有以下代码:

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.


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.

最后一行 - “堆栈应该选择一个每对孩子的默认距离"

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VStack 围绕图像间距,但不围绕文本 的相关文章

随机推荐