0Pricing
SwiftUI Academy · درس

شبكات متكيفة باستخدام LazyVGrid

رتّب البطاقات في أعمدة شبكة مرنة

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

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

Why a Grid?

Stacks give you rows or columns, but a LazyVGrid arranges items into neat rows and columns, like a photo album. 🖼️

Define the Columns

A LazyVGrid needs a columns array of GridItem values that describe how many tracks to lay out.

let columns = [GridItem(), GridItem()]
LazyVGrid(columns: columns) {
    ForEach(items) { Cell($0) }
}

Flexible Items

A GridItem(.flexible()) stretches to share space evenly, so two flexible items make two equal columns.

let columns = [
    GridItem(.flexible()),
    GridItem(.flexible())
]

Fixed Width Tracks

Use GridItem(.fixed(80)) when you want a column to stay exactly 80 points wide no matter the screen.

let columns = [GridItem(.fixed(80))]

Truly Adaptive

The magic option is .adaptive(minimum:): it fits as many columns as will fit, adjusting to any screen size.

let columns = [
    GridItem(.adaptive(minimum: 100))
]

Always Inside a Scroll

Wrap your LazyVGrid in a ScrollView so the grid can grow past the screen and load cells lazily.

ScrollView {
    LazyVGrid(columns: columns) {
        ForEach(items) { Cell($0) }
    }
}

Spacing Between Cells

Tune the gaps with a spacing argument on the grid and on each GridItem for tidy, balanced cells.

LazyVGrid(columns: columns, spacing: 16) {
    ForEach(items) { Cell($0) }
}

Cells Are Just Views

Each item in the ForEach becomes a cell, so any view works: an image, a card, or a labeled button.

ForEach(photos) { photo in
    Image(photo.name)
        .resizable()
}

Lazy by Name

Like other lazy containers, LazyVGrid builds cells as they scroll in, so large galleries stay smooth.

Horizontal Cousin

Need columns of fixed rows scrolling sideways? LazyHGrid is the horizontal counterpart with the same GridItem API.

Responsive Layouts

One adaptive grid looks great on a phone and an iPad, since columns reflow automatically to fill the space. ✨

Quick Check

Think about which GridItem reacts to screen size.

Recap

You learned to build flexible, fixed, and adaptive grids with LazyVGrid inside a ScrollView for responsive layouts. 🎉

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

هل درس «شبكات متكيفة باستخدام LazyVGrid» مجاني؟

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

ماذا ستتعلم في «شبكات متكيفة باستخدام LazyVGrid»؟

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

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

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

كم من الوقت يستغرق درس «شبكات متكيفة باستخدام LazyVGrid»؟

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

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

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

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

  1. ‏ScrollView الأفقي والرأسي
  2. ‏LazyVStack وLazyHStack
  3. شبكات متكيفة باستخدام LazyVGrid
  4. ‏ScrollView Reader والمراسي
← العودة إلى SwiftUI Academy