0Pricing
SwiftUI Academy · درس

ترتيب View عمودياً

اجمع View من الأعلى إلى الأسفل باستخدام VStack

ترتيب View عمودياً درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why You Need Stacks

A SwiftUI body can return only one view. To show several views together, you wrap them in a container that arranges them for you. 📦

Meet VStack

A VStack stacks its child views vertically, top to bottom. It is your go-to container for column-style layouts like a title above a subtitle.

Your First VStack

Place views inside the VStack braces and they appear in order, each on its own line. The first child sits at the top.

VStack {
    Text("Hello")
    Text("World")
}

Order Matters

Children render in the exact order you write them. Swap two lines of code and the views swap places on screen. Top of the code is top of the column.

Centered by Default

By default a VStack centers its children horizontally and shrinks to fit its content, like a tidy little column hugging its views.

Mixing View Types

A VStack does not care what kind of views it holds. You can freely mix a Text, an Image, and a Button in the same vertical stack.

VStack {
    Image(systemName: "star")
    Text("Favorite")
}

How Many Views Fit?

A stack can hold up to ten direct children at once. That is plenty for most screens, and you can always nest stacks for more.

Nesting Stacks

You can put a VStack inside another VStack to build richer layouts. Nesting lets you group related views so they move together.

VStack {
    Text("Title")
    VStack {
        Text("Line 1")
        Text("Line 2")
    }
}

Stacks Are Views Too

A VStack is itself a view, so you can apply modifiers like padding or background to the whole stack at once. The group acts as one unit.

Returning a VStack from body

Since body needs a single view, returning a VStack is the classic way to show many views. The stack becomes that one returned view.

var body: some View {
    VStack {
        Text("One")
        Text("Two")
    }
}

When to Reach for VStack

Use a VStack whenever items should read top to bottom: a heading over body text, a label over a value, or a form laid out in rows.

Quick Check

Let's make sure VStack ordering is clear.

Recap: Vertical Stacking

Nice work! A VStack arranges views top to bottom in code order, centers them by default, and acts as one view you can style or nest. 🎉

الأسئلة الشائعة

هل درس «ترتيب View عمودياً» مجاني؟

نعم — نص درس «ترتيب View عمودياً» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «ترتيب View عمودياً»؟

اجمع View من الأعلى إلى الأسفل باستخدام VStack تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «ترتيب View عمودياً»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ترتيب View عمودياً
  2. الصفوف باستخدام HStack
  3. التكديس باستخدام ZStack
  4. المسافات والمحاذاة في حاويات التكديس
← العودة إلى SwiftUI Academy