0Pricing
SwiftUI Academy · Aula

Escolhendo valores com Slider

Escolha um número em um intervalo usando um controle deslizante.

Escolhendo valores com Slider é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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. 🎚️

Perguntas Frequentes

A aula “Escolhendo valores com Slider” é grátis?

Sim — o texto completo de “Escolhendo valores com Slider” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.

O que vou aprender em “Escolhendo valores com Slider”?

Escolha um número em um intervalo usando um controle deslizante. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar SwiftUI Academy?

Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.

Quanto tempo leva a aula “Escolhendo valores com Slider”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de SwiftUI Academy?

Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Ativado e desativado com Toggle
  2. Escolhendo valores com Slider
  3. Incrementando com Stepper
  4. Selecionando opções com Picker
← Voltar para SwiftUI Academy