Skip to content
Toggle Group preview
Rendered from the SwiftUI source on this page.

Toggle Group

From syxUI — written for both platforms, not translated between them.

A grouped settings card with labelled rows and iOS green switches.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

ToggleGroupCard.swift
// Toggle Group · syxUI · https://syxui.dev/components/sel-toggle-group
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Grouped settings toggles - iOS green switches
struct ToggleGroupCard: View {
    @State private var push = true
    @State private var faceID = true
    @State private var darkMode = false
    var body: some View {
        VStack(spacing: 0) {
            row("Push notifications", "Alerts, reminders & updates", $push)
            Divider()
            row("Face ID", "Unlock instantly with your face", $faceID)
            Divider()
            row("Dark appearance", "Always use the dark theme", $darkMode)
        }.formaCard(6)
    }
    func row(_ t: String, _ s: String, _ isOn: Binding<Bool>) -> some View {
        HStack {
            VStack(alignment: .leading, spacing: 2) {
                Text(t).font(.system(size: 15, weight: .medium))
                Text(s).font(.system(size: 12)).foregroundStyle(.secondary)
            }
            Spacer()
            Toggle("", isOn: isOn).labelsHidden().tint(Color(red: 0.20, green: 0.78, blue: 0.35))
        }.padding(.horizontal, 12).padding(.vertical, 10)
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • formaCard

Requires iOS 17