0Pricing
SwiftUI Academy · Ders

Toggle ile Açma ve Kapatma

Bir Toggle’ı boole ayarına bağlayın.

Toggle ile Açma ve Kapatma, CoddyKit'te ücretsiz bir SwiftUI Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, SwiftUI Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. SwiftUI Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Meet the Toggle

A Toggle is SwiftUI's on/off switch. It is perfect for settings like notifications, dark mode, or any yes-or-no choice. 🔘

Toggle Needs a Boolean

Every Toggle reflects a Bool value. When the switch is on the value is true; when it is off the value is false. They stay in sync.

Store It in @State

Hold the on/off value in a @State property so the view can read and update it as the user flips the switch.

@State private var isOn = false

Bind with the Dollar Sign

Connect the Toggle to your state using the dollar sign. That creates a two-way binding so flips update the value automatically.

Toggle("Notifications", isOn: $isOn)

Give It a Clear Label

The first argument is the label users read next to the switch. Keep it short and describe exactly what the toggle controls.

Toggle("Dark Mode", isOn: $isDark)

React to the Value

Read the boolean anywhere in your body to react to the switch. Here the text changes based on whether the toggle is on.

Text(isOn ? "On" : "Off")

Put It in a Form

Toggles look most at home inside a Form, where they automatically gain the familiar iOS settings-row styling.

Form {
    Toggle("Wi-Fi", isOn: $wifiOn)
}

A Richer Label View

Need an icon too? Use the closure form so the label can be any view, like a Label with an SF Symbol.

Toggle(isOn: $isOn) {
    Label("Sound", systemImage: "speaker")
}

Style the Switch

Change the look with toggleStyle. The button style turns it into a tappable button instead of the default switch.

Toggle("Star", isOn: $isOn)
    .toggleStyle(.button)

Tint the Track

Set the on-color of the switch with the tint modifier, so it matches your app's accent and feels branded.

Toggle("On", isOn: $isOn)
    .tint(.green)

The Full View

Here it all comes together: one boolean, one Toggle bound to it, and a Text that responds to every flip.

struct SettingsView: View {
    @State private var isOn = false
    var body: some View {
        Toggle("Alerts", isOn: $isOn)
        Text(isOn ? "On" : "Off")
    }
}

Quick Check

How do you connect a Toggle to a boolean state value?

Recap

A Toggle binds to a Bool with the dollar sign, flips it on tap, and lets you react, style, and tint the switch. 🔁

Sıkça Sorulan Sorular

“Toggle ile Açma ve Kapatma” dersi ücretsiz mi?

Evet — “Toggle ile Açma ve Kapatma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve SwiftUI Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. SwiftUI Academy kursu toplamda 4 dersten oluşur.

“Toggle ile Açma ve Kapatma” dersinde ne öğreneceğim?

Bir Toggle’ı boole ayarına bağlayın. SwiftUI Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

SwiftUI Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te SwiftUI Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“Toggle ile Açma ve Kapatma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu SwiftUI Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her SwiftUI Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Toggle ile Açma ve Kapatma
  2. Slider ile Değer Seçme
  3. Stepper ile Artırma
  4. Picker ile Seçenek Belirleme
← SwiftUI Academy Sayfasına Dön