0Pricing
SwiftUI Academy · درس

النص متعدد الأسطر والمحاذاة

تحكّم في حدود الأسطر والتفاف النص ومحاذاته

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

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

When Text Gets Long

Short labels fit on one line, but paragraphs wrap. This lesson shows how to control wrapping, line limits, and alignment for longer text. 📝

Text Wraps by Default

SwiftUI wraps long text onto multiple lines automatically when there is room. You usually do not need to do anything for basic wrapping.

Text("A fairly long sentence that will wrap onto more than one line.")

Limiting Lines

The lineLimit modifier caps how many lines show. Extra text is truncated with an ellipsis, which is great for previews and cards.

Text(longBio)
    .lineLimit(2)

Truncation Mode

Control where the cut happens with truncationMode. Choose .tail, .head, or .middle depending on which part matters most.

Text(path)
    .lineLimit(1)
    .truncationMode(.middle)

Aligning Multiline Text

Use multilineTextAlignment to align wrapped lines left, center, or trailing. It only affects text that spans more than one line.

Text(quote)
    .multilineTextAlignment(.center)

Frame Versus Text Alignment

Remember the difference: frame alignment positions the whole block, while multilineTextAlignment arranges lines inside that block.

Centering a Block

To center a block and its lines, give it a wide frame and a center text alignment together. Both work as a pair.

Text(notice)
    .multilineTextAlignment(.center)
    .frame(maxWidth: .infinity)

Line Spacing

Add breathing room between lines with lineSpacing. A few extra points often makes dense paragraphs much easier to read.

Text(article)
    .lineSpacing(6)

Allowing Tight Layout

When space is tight, minimumScaleFactor lets text shrink instead of truncating, keeping the whole message visible.

Text(headline)
    .lineLimit(1)
    .minimumScaleFactor(0.7)

Fixed Size to Avoid Clipping

If wrapping text gets squeezed, fixedSize tells it to keep its ideal height so nothing gets unexpectedly clipped.

Text(message)
    .fixedSize(horizontal: false, vertical: true)

Putting It Together

Combine lineLimit, alignment, and spacing to craft readable cards. Small tweaks add up to a polished reading experience.

Quick Check

Which modifier aligns wrapped lines of text?

Lesson Recap

You shaped long text with lineLimit, truncation, alignment, and spacing. These tools keep paragraphs tidy and easy to read. 👍

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

هل درس «النص متعدد الأسطر والمحاذاة» مجاني؟

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

ماذا ستتعلم في «النص متعدد الأسطر والمحاذاة»؟

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

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

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

كم من الوقت يستغرق درس «النص متعدد الأسطر والمحاذاة»؟

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

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

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

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

  1. الخط والسُمك واللون
  2. النص متعدد الأسطر والمحاذاة
  3. تحميل الصور من الأصول
  4. استخدام SF Symbols
← العودة إلى SwiftUI Academy