0Pricing
SwiftUI Academy · درس

تحديد أحجام View باستخدام frame

حدّد قيود العرض والارتفاع والحد الأدنى والأقصى

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

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

Views Size Themselves

By default a SwiftUI view is exactly as big as its content needs. When you want a specific size, you reach for the frame modifier to ask for one.

A Fixed Width and Height

The frame modifier lets you request an exact size. Here the text is placed inside a box that is 200 points wide and 80 points tall.

Text("Card")
    .frame(width: 200, height: 80)

Width Only

You do not have to set both dimensions. Give only a width and the height stays natural, sized to fit the content as usual.

Text("Wide")
    .frame(width: 250)

Filling Available Space

Set maxWidth to infinity to let a view stretch across all the space its parent offers. This is great for full-width buttons and rows.

Text("Stretch")
    .frame(maxWidth: .infinity)

Aligning Inside the Frame

A roomy frame centers its content by default. The alignment argument moves that content, like pinning text to the leading edge.

Text("Left")
    .frame(maxWidth: .infinity, alignment: .leading)

Minimum Sizes

Use minWidth or minHeight to guarantee a view never shrinks below a floor, even when content is tiny. Handy for consistent tap targets.

Text("OK")
    .frame(minWidth: 120)

Maximum Sizes

The maxWidth and maxHeight values cap how large a flexible view can grow, so it stretches only up to a limit you choose.

Text("Capped")
    .frame(maxWidth: 400)

Combining Min and Max

Mix minWidth and maxWidth for a flexible range. The view grows with its parent but stays between a comfortable lower and upper bound.

Text("Flexible")
    .frame(minWidth: 100, maxWidth: 300)

Frame and Background Together

A frame defines the area a background fills. Set a frame, then add a color, and the whole sized region is painted, not just the text.

Text("Tile")
    .frame(width: 120, height: 120)
    .background(.mint)

Frame Wraps, It Does Not Clip

A frame proposes a size but never trims content by itself. If content is larger than the frame, it can spill out unless you also clip it.

Frame Plus Padding

Combine the two tools for polished layouts: a frame sets the overall size and padding adds the inner breathing room around the content.

Text("Spaced")
    .padding()
    .frame(maxWidth: .infinity)

Quick Check

Check your understanding of the frame modifier.

Recap

Great progress! You can now use frame to set exact sizes, flexible ranges, fill space with infinity, and align content inside the area.

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

هل درس «تحديد أحجام View باستخدام frame» مجاني؟

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

ماذا ستتعلم في «تحديد أحجام View باستخدام frame»؟

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

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

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

كم من الوقت يستغرق درس «تحديد أحجام View باستخدام frame»؟

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

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

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

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

  1. إضافة حشوة حول View
  2. تحديد أحجام View باستخدام frame
  3. الخلفيات ونصف قطر الزوايا
  4. Spacer وأولوية التخطيط
← العودة إلى SwiftUI Academy