Skip to content
Legal Sections preview
Rendered from the SwiftUI source on this page.

Legal Sections

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

Numbered terms / legal sections that expand.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccLegal.swift
// Legal Sections · syxUI · https://syxui.dev/components/acc-legal
// 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)
    }
}

// Legal / terms numbered accordion
struct AccLegal: View {
    @State private var open = 0
    let secs = [("1. Acceptance of Terms", "By accessing this service you agree to be bound by these terms and all applicable laws."),
                        ("2. Use License", "Permission is granted to temporarily use the materials for personal, non-commercial use."),
                        ("3. Privacy", "Your use is also governed by our Privacy Policy.")]
    var body: some View {
        VStack(spacing: 0) {
            ForEach(Array(secs.enumerated()), id: \.offset) { i, s in
                HStack {
                    Text(s.0).font(.system(size: 14, weight: .semibold))
                    Spacer()
                    Image(systemName: "chevron.down").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open == i ? 180 : 0))
                }.padding(.vertical, 12).contentShape(Rectangle()).onTapGesture { open = open == i ? -1 : i }
                if open == i { Text(s.1).font(.system(size: 13)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding(.bottom, 12) }
                if i < secs.count - 1 { Divider() }
            }
        }.formaCard(16).frame(width: 340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17