0Pricing
SwiftUI Academy · درس

النوع الديناميكي والخطوط المتدرجة

ادعم النصوص الأكبر من دون إفساد التخطيط

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

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

What Is Dynamic Type?

Dynamic Type lets users pick their preferred text size system-wide. Your app should respect it, not force one fixed size. 🔤

Use Text Styles

Pick semantic text styles like .title or .body instead of fixed point sizes. These scale automatically with the user's setting.

Text("Welcome")
    .font(.title)
Text("Details here")
    .font(.body)

Why Not Fixed Sizes

A hard-coded .font(.system(size: 17)) ignores the user's choice and stays small. Text styles adapt; fixed numbers don't.

Text("Stuck small")
    .font(.system(size: 17))

Scaling Custom Fonts

Have a brand font? Use .font(.custom:size:relativeTo:) so it still scales with a chosen text style.

Text("Brand")
    .font(.custom("Avenir", size: 17, relativeTo: .body))

The ScaledMetric Wrapper

Need a spacing or image size to grow with text? @ScaledMetric scales any number alongside Dynamic Type.

@ScaledMetric var iconSize = 24
Image(systemName: "star").frame(width: iconSize)

Let Text Wrap

Big text needs room. Avoid lineLimit(1) on important labels, or long words will be cut off with an ellipsis.

Text(longTitle)
    .lineLimit(2)

Allow Tighter Fitting

When space is truly tight, minimumScaleFactor lets text shrink a little before truncating, keeping it readable.

Text(price)
    .minimumScaleFactor(0.7)

Preview Large Sizes

Use dynamicTypeSize in a preview to simulate the largest setting and catch broken layouts early.

#Preview {
    ContentView()
        .dynamicTypeSize(.accessibility3)
}

Cap the Range If Needed

You can limit how far text scales with dynamicTypeSize(...), but cap sparingly so you don't shut out users who need more.

VStack { }
    .dynamicTypeSize(...DynamicTypeSize.accessibility1)

Stacks Over Fixed Frames

Prefer flexible stacks over rigid heights. A fixed frame can clip large text, while a stack grows to fit.

Test at Both Ends

Check your app at the smallest and the largest Dynamic Type sizes. If both read well, most users in between will too.

Quick Check

You want a custom brand font to grow with the user's text size. What do you use?

Recap

You made text adapt: choose semantic text styles, scale custom fonts and metrics, let text wrap, and test the largest size. 👍

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

هل درس «النوع الديناميكي والخطوط المتدرجة» مجاني؟

نعم — نص درس «النوع الديناميكي والخطوط المتدرجة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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. ‏VoiceOver وتسميات إمكانية الوصول
  2. النوع الديناميكي والخطوط المتدرجة
  3. توطين السلاسل وString Catalogs
  4. التكيف مع الوضع الفاتح والداكن
← العودة إلى SwiftUI Academy