前言
個人學習 SwiftUI 的記錄,如有錯誤,請指教哈!
VStack
縱向佈局, 用來包裹其他 View, 從上到下的縱向佈局
先上效果圖
代碼
import SwiftUI
struct XQVStackView: View {
var body: some View {
VStack {
// 橫向佈局
// alignment: 佈局對齊格式, 默認爲 .center
// spacing: 子 View 的間距
VStack.init(alignment: .trailing, spacing: 10) {
Text("我是第一個asdasdsadLab")
Text("我是第二個Lab")
}
.padding()
.background(Color.orange)
.cornerRadius(20)
.shadow(radius: 10)
VStack {
Text("我是第一個Labasdasdasdasdasd")
Text("我是第二個Lab")
}
.padding()
.background(Color.orange)
.cornerRadius(20)
.shadow(radius: 10)
.padding(.top, 10)
VStack {
Text("我在上")
// 如何把 View 分到 上下兩邊呢
// 增加 Spacer()
Spacer()
Text("你在下")
}
// 固定大小
.frame(width: 200, height: 100)
.padding()
.background(Color.orange)
.cornerRadius(20)
.shadow(radius: 10)
.padding(.top, 10)
}
}
}