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

Settings Group

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

A settings section that expands to reveal toggles.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccSettings.swift
// Settings Group · syxUI · https://syxui.dev/components/acc-settings
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let accBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

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 with an expandable section
struct AccSettings: View {
    @State private var open = true
    @State private var wifi = true
    @State private var cellular = false
    var body: some View {
        VStack(spacing: 0) {
            HStack {
                Image(systemName: "network").font(.system(size: 15)).foregroundStyle(accBlue).frame(width: 26)
                Text("Connectivity").font(.system(size: 15, weight: .medium))
                Spacer()
                Image(systemName: "chevron.down").font(.system(size: 12, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open ? 180 : 0))
            }.padding(.vertical, 13).contentShape(Rectangle()).onTapGesture { open.toggle() }
            if open {
                Divider()
                Toggle(isOn: $wifi) { Text("Wi-Fi").font(.system(size: 15)) }.tint(accBlue).padding(.vertical, 9)
                Divider()
                Toggle(isOn: $cellular) { Text("Cellular Data").font(.system(size: 15)) }.tint(accBlue).padding(.vertical, 9)
            }
        }.formaCard(16).frame(width: 340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17