如何在swiftUI中调整HStack元素之间的间距?

时间:2019-06-08 12:25:48

标签: ios swift swiftui hstack vstack

我添加了spacer(minLength:5),但是它需要minlenght 我可以指定文本之间的间距。 我已经附上了一个屏幕截图,以供参考,我希望减少内部hstack之间的间距。

HStack {
Image("Rhea").resizable().cornerRadius(25).frame(width: 50.0, height: 50.0)
    VStack(alignment: .leading) {
        Text("How to enjoy your life without money").bold().font(.system(size: 20))
        HStack {
            Text("Lets create")
            Spacer(minLength: 5)
            Text("3K views")
            Spacer(minLength: 5)
            Text("3 hours ago")
        }
    }
}

enter image description here

2 个答案:

答案 0 :(得分:1)

将间距属性添加到HStack本身。间距为10:

HStack {
Image("Rhea").resizable().cornerRadius(25).frame(width: 50.0, height: 50.0)
    VStack(alignment: .leading) {
        Text("How to enjoy your life without money").bold().font(.system(size: 20))
        HStack(spacing: 10) {
            Text("Lets create")
            Text("3K views")
            Text("3 hours ago")
        }
    }
}

答案 1 :(得分:0)

您可以像下面这样使用时设置默认的HStack属性。

VStack(alignment: .leading) {
                Text("How to enjoy your life without money").bold().font(.system(size: 20))
                HStack (alignment: .center, spacing: 0, content: {
                    Text("Lets create")
                    Text("3K views")
                    Text("3 hours ago")
                })
            }

enter image description here