Stacks

HStack

struct HStack
A view that arranges its children in a horizontal line.

init(alignment: VerticalAlignment, spacing: CGFloat?, content: () -> Content)
Creates an instance with the given spacing and vertical alignment.

struct VerticalAlignment
An alignment position along the horizontal axis.

VStack

struct VStack
A view that arranges its children in a vertical line.

init(alignment: HorizontalAlignment, spacing: CGFloat?, content: () -> Content)
Creates an instance with the given spacing and horizontal alignment.

struct HorizontalAlignment
An alignment position along the horizontal axis.

ZStack

struct ZStack
A view that overlays its children, aligning them in both axes.

init(alignment: Alignment, content: () -> Content)
Creates an instance with the given alignment.

struct Alignment
An alignment in both axes.

//纵向Y轴
VStack {
     Text("123456")
     Spacer()  //隔开两个元素
     Image(systemName: "snow")
}
.background(Color.gray, alignment: .center)
.frame(width: 300, height: 60, alignment: .center)
.padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
//横向X轴
HStack.init(alignment: .center, spacing: 20) {
     Text("123456")
     Divider()  //添加分割线
     Image(systemName: "snow")
}
//Z轴,后边会覆盖前边
ZStack.init {
     Text("123456")
     Image(systemName: "snow")
}
截屏2020-04-0216.12.49.png

你可能感兴趣的:(Stacks)