
FAQ Accordion
From syxUI — written for both platforms, not translated between them.
A classic FAQ list where one answer expands at a time.
Accordions · SwiftUI · iOS 17
- accordion
- swiftui
The actual source
AccFAQ.swift
// FAQ Accordion · syxUI · https://syxui.dev/components/acc-faq
// 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)
}
}
// Classic FAQ accordion, first item open
struct AccFAQ: View {
@State private var open = 0
let qs = [("How do I cancel my subscription?", "Open Settings → Subscription and tap Cancel. You keep access until the period ends."),
("Can I get a refund?", "Refunds are available within 14 days of purchase."),
("Is there a student discount?", "Yes - 50% off with a valid .edu email.")]
var body: some View {
VStack(spacing: 0) {
ForEach(Array(qs.enumerated()), id: \.offset) { i, q in
HStack {
Text(q.0).font(.system(size: 15, weight: .medium))
Spacer()
Image(systemName: "chevron.down").font(.system(size: 12, weight: .semibold)).foregroundStyle(.secondary).rotationEffect(.degrees(open == i ? 180 : 0))
}.padding(.vertical, 14).contentShape(Rectangle()).onTapGesture { open = open == i ? -1 : i }
if open == i { Text(q.1).font(.system(size: 14)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding(.bottom, 14) }
if i < qs.count - 1 { Divider() }
}
}.formaCard(16).frame(width: 340)
}
}
iOS 17 · No dependencies
Dependencies
- SwiftUI
- No external dependencies
Requires iOS 17

