
FAQ Accordion
From syxUI — written for both platforms, not translated between them.
A self-contained faq accordion — SwiftUI, styled from system tokens.
Accordions · SwiftUI · iOS 17
- accordion
- swiftui
The actual source
FAQAccordion.swift
// FAQ Accordion · syxUI · https://syxui.dev/components/accordion-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)
}
}
// Accordion - FAQ
struct FAQAccordion: View {
@State private var open = 0
let items = [("How does billing work?", "You're charged monthly and can switch plans anytime. Unused days are prorated."),
("Can I cancel whenever?", "Yes - cancel in Settings and keep access until the period ends."),
("Do you offer refunds?", "14 days, no questions asked, on your first purchase.")]
var body: some View {
VStack(spacing: 0) {
ForEach(items.indices, id: \.self) { i in
VStack(alignment: .leading, spacing: 0) {
Button { withAnimation(.snappy(duration: 0.25)) { open = open == i ? -1 : i } } label: {
HStack {
Text(items[i].0).font(.system(size: 15, weight: .medium)).foregroundStyle(.primary)
Spacer()
Image(systemName: open == i ? "minus" : "plus").font(.system(size: 13, weight: .semibold)).foregroundStyle(.secondary)
}.padding(.vertical, 16)
}.buttonStyle(.plain)
if open == i {
Text(items[i].1).font(.system(size: 14)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true).padding(.bottom, 16)
}
if i < items.count - 1 { Divider() }
}
}
}.formaCard()
}
}
iOS 17 · 1 dependencies
Dependencies
- SwiftUI
- formaCard
Requires iOS 17

