0Pricing
SwiftUI Academy · Lezione

Incrementare con Stepper

Regolare i valori verso l'alto o verso il basso con uno stepper.

Incrementare con Stepper è una lezione SwiftUI Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento SwiftUI Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso SwiftUI Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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. ➕➖

Domande Frequenti

La lezione «Incrementare con Stepper» è gratuita?

Sì — il testo completo di «Incrementare con Stepper» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso SwiftUI Academy, passa a CoddyKit PRO. Il corso SwiftUI Academy include 4 lezioni in totale.

Cosa imparerò in «Incrementare con Stepper»?

Regolare i valori verso l'alto o verso il basso con uno stepper. Eserciti SwiftUI Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare SwiftUI Academy?

Non è richiesta alcuna esperienza precedente. SwiftUI Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Incrementare con Stepper»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione SwiftUI Academy?

Sì. Ogni lezione SwiftUI Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Attivare e disattivare con Toggle
  2. Scegliere valori con Slider
  3. Incrementare con Stepper
  4. Selezionare opzioni con Picker
← Torna a SwiftUI Academy