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

Toggle Rows

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

Grouped rows with iOS switches.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

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

import SwiftUI

let listGreen = Color(red: 0.20, green: 0.78, blue: 0.35)

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)
    }
}

// Toggle rows
struct ToggleRowCard: View {
    @State private var a = true
    @State private var b = false
    var body: some View {
        VStack(spacing: 0) {
            HStack { VStack(alignment: .leading, spacing: 1) { Text("Include Steps").font(.system(size: 15)); Text("In activity calculation").font(.system(size: 12)).foregroundStyle(.secondary) }; Spacer(); Toggle("", isOn: $a).labelsHidden().tint(listGreen) }.padding(.vertical, 8)
            Divider()
            HStack { VStack(alignment: .leading, spacing: 1) { Text("Sync with Health").font(.system(size: 15)); Text("Two-way sync").font(.system(size: 12)).foregroundStyle(.secondary) }; Spacer(); Toggle("", isOn: $b).labelsHidden().tint(listGreen) }.padding(.vertical, 8)
        }.formaCard(14).frame(width: 330)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17