0Pricing
SwiftUI Academy · Lekcja

Wybieranie wartości za pomocą Slider

Proszę wybierać liczbę z zakresu za pomocą suwaka.

Wybieranie wartości za pomocą Slider to bezpłatna lekcja SwiftUI Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej SwiftUI Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

Meet the Slider

A Slider lets users drag to pick a number from a range. Think volume, brightness, or any smooth, continuous value. 🎚️

Sliders Hold a Number

A Slider works with a Double. As the user drags the thumb, that value updates continuously across its range.

@State private var volume = 0.5

Bind to State

Connect the Slider to your value with the dollar sign binding, exactly like Toggle. Dragging then updates the number live.

Slider(value: $volume)

Set the Range

By default a Slider runs from 0 to 1. Pass an explicit range to choose your own minimum and maximum.

Slider(value: $volume, in: 0...100)

Snap with a Step

Add a step so the value jumps in fixed increments instead of any decimal, which is great for whole numbers.

Slider(value: $level, in: 0...10, step: 1)

Show the Current Value

Read the bound number to display it, so users see exactly where the slider sits as they drag.

Text("Volume: \(Int(volume))")

Add Edge Labels

Use the closure parameters to put labels at each end of the track, like icons for quiet and loud.

Slider(value: $volume, in: 0...100) {
    Text("Volume")
}

Tint the Track

Color the filled portion of the slider with the tint modifier so it matches your app's style.

Slider(value: $volume).tint(.orange)

Detect Drag Start and End

The onEditingChanged closure fires when dragging begins and ends, handy for committing a value once.

Slider(value: $v) { editing in
    isDragging = editing
}

Drive Other Views

The slider value can control anything. Here it sets a circle's scale, so the shape grows as you drag.

Circle().scaleEffect(volume)

The Full View

This view ties it together: a Slider over a custom range plus a Text that reflects the live value.

struct VolumeView: View {
    @State private var volume = 50.0
    var body: some View {
        Slider(value: $volume, in: 0...100)
        Text("\(Int(volume))")
    }
}

Quick Check

How do you make a Slider produce whole numbers from 0 to 10?

Recap

A Slider binds to a Double, takes an in range and optional step, and updates live so other views can react. 🎚️

Często zadawane pytania

Czy lekcja „Wybieranie wartości za pomocą Slider” jest bezpłatna?

Tak — pełny tekst „Wybieranie wartości za pomocą Slider” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu SwiftUI Academy, przejdź na CoddyKit PRO. Kurs SwiftUI Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Wybieranie wartości za pomocą Slider”?

Proszę wybierać liczbę z zakresu za pomocą suwaka. Ćwiczysz SwiftUI Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć SwiftUI Academy?

Nie wymagamy żadnego doświadczenia. SwiftUI Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Wybieranie wartości za pomocą Slider”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji SwiftUI Academy?

Tak. Każda lekcja SwiftUI Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Włączanie i wyłączanie za pomocą Toggle
  2. Wybieranie wartości za pomocą Slider
  3. Zwiększanie i zmniejszanie za pomocą Stepper
  4. Wybieranie opcji za pomocą Picker
← Powrót do SwiftUI Academy