Stepper で値を増減する
Stepper で値を上下に調整します。
「Stepper で値を増減する」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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 = 1Bind 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時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「Stepper で値を増減する」で何を学びますか?
Stepper で値を上下に調整します。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「Stepper で値を増減する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Toggle によるオン/オフ
- Slider で値を選択する
- Stepper で値を増減する
- Picker で選択肢を選ぶ