0Pricing
SwiftUI Academy · درس

زيادة القيم باستخدام Stepper

اضبط القيم بالزيادة والنقصان باستخدام stepper

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

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

Meet the Stepper

A Stepper shows minus and plus buttons to nudge a value up or down. It is ideal for quantities like item counts. ➕

Stepper Holds a Number

Like Slider, a Stepper edits a number. Tapping plus increases it and tapping minus decreases it by one step.

@State private var count = 1

Bind to State

Connect the value with the dollar sign binding and give it a label. SwiftUI handles the plus and minus taps for you.

Stepper("Quantity", value: $count)

Set a Range

Pass an in range to clamp the value. The buttons disable automatically when you hit the minimum or maximum.

Stepper("Count", value: $count, in: 0...10)

Choose the Step Size

Add a step to change how much each tap moves the value, like jumping by five instead of one.

Stepper("Score", value: $count, in: 0...100, step: 5)

Show the Value

You usually want to display the current number. Interpolate it into the label so users see the count update.

Stepper("Items: \(count)", value: $count)

Custom Increment Actions

Need full control? Use the onIncrement and onDecrement closures to run your own logic on each tap.

Stepper("Adjust") {
    count += 2
} onDecrement: {
    count -= 2
}

Stepper in a Form

Drop a Stepper into a Form row for a tidy settings look, the same way Toggle and Slider fit there.

Form {
    Stepper("Servings", value: $count)
}

A Richer Label

The label can be any view via the closure form, so you can pair text with an icon for clarity.

Stepper(value: $count) {
    Label("Cups", systemImage: "cup.and.saucer")
}

React to Changes

Other views update automatically when the count changes. Here a Text repeats based on the value.

Text(String(repeating: "⭐️", count: count))

The Full View

Everything together: a clamped Stepper with a step plus a label that shows the live count.

struct CartView: View {
    @State private var count = 1
    var body: some View {
        Stepper("Qty: \(count)", value: $count, in: 1...9)
    }
}

Quick Check

What happens when a Stepper value reaches the top of its range?

Recap

A Stepper nudges a number with plus and minus, supports an in range and step, and clamps at the edges. ➕➖

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

هل درس «زيادة القيم باستخدام Stepper» مجاني؟

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

ماذا ستتعلم في «زيادة القيم باستخدام Stepper»؟

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

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

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

كم من الوقت يستغرق درس «زيادة القيم باستخدام Stepper»؟

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

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

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

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

  1. التشغيل والإيقاف باستخدام Toggle
  2. اختيار القيم باستخدام Slider
  3. زيادة القيم باستخدام Stepper
  4. اختيار الخيارات باستخدام Picker
← العودة إلى SwiftUI Academy