ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
VStack က child view တွေကို vertical (အပေါ်-အောက်) စီပေးပါတယ် — HStack ကတော့ horizontal (ဘယ်-ညာ) စီပေးပါတယ်။ ZStack ကတော့ child view တွေကို overlap (တစ်ခုပေါ်တစ်ခု ထပ်) ဖြစ်အောင် placement လုပ်ပေးပါတယ် (ဥပမာ - image ပေါ်မှာ text overlay)။ Modifier က view တစ်ခုချင်းစီရဲ့ appearance/behavior (padding, frame, background color, onTapGesture) ကို chain (`.padding(16).background(Color.blue)`) ဖြင့် customize လုပ်ဖို့ toolkit ပါ.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Login screen တစ်ခု ဒီဇိုင်းရေးရင် — `VStack` ထဲမှာ logo (Image), email TextField, password TextField, login Button ကို vertical စီထားနိုင်ပါတယ် — `.padding(16)` ကို VStack ပေါ် ထည့်ရင် screen edge နဲ့ content ကြား space ရအောင် ထားလို့ရပါတယ်.
အတူတူ ကြည့်မယ်
struct LoginScreen: View {
var body: some View {
VStack {
Text("Welcome Back")
.font(.title)
Spacer().frame(height: 16)
HStack {
Image(systemName: "envelope")
Text("email@example.com")
}
}
.padding()
}
}Simulator ပေါ်မှာ 'Welcome Back' text အောက်မှာ email icon + text ကို row အနေနဲ့ တွေ့ရမည်။၅ မိနစ် စမ်းကြည့်
`LoginScreen` ကို ကိုယ်တိုင် expand လုပ်ကြည့်ပါ — email/password TextField ၂ ခုနဲ့ Login Button ကို VStack ထဲ ထပ်ထည့်ပြီး Simulator ပေါ် run ကြည့်ပါ။
သတိလေးတစ်ချက်
`.frame(maxWidth: .infinity)` ကို nested view တွေမှာ overuse ရင် layout ရဲ့ actual size ကို ခန့်မှန်းရခက်ခဲသွားနိုင်ပါတယ် — root level မှာသာ သုံးပြီး child views တွေမှာ specific size သုံးသင့်ပါတယ်။