Skip to content
Plus / Minus preview
Rendered from the SwiftUI source on this page.

Plus / Minus

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

Bordered expandable rows with a plus / minus indicator.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccPlusMinus.swift
// Plus / Minus · syxUI · https://syxui.dev/components/acc-plus-minus
// 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)

// Plus / minus indicator accordion
struct AccPlusMinus: View {
    @State private var open = 1
    let items = [("Shipping & delivery", "Free standard shipping on orders over $50. Delivery in 3–5 business days."),
                         ("Returns policy", "Return unworn items within 30 days for a full refund."),
                         ("Warranty", "All products include a 1-year limited warranty.")]
    var body: some View {
        VStack(spacing: 10) {
            ForEach(Array(items.enumerated()), id: \.offset) { i, it in
                VStack(spacing: 0) {
                    HStack {
                        Text(it.0).font(.system(size: 15, weight: .semibold))
                        Spacer()
                        Image(systemName: open == i ? "minus" : "plus").font(.system(size: 13, weight: .bold)).foregroundStyle(accBlue)
                    }.padding(14).contentShape(Rectangle()).onTapGesture { open = open == i ? -1 : i }
                    if open == i { Text(it.1).font(.system(size: 14)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding([.horizontal, .bottom], 14) }
                }
                .background(Color.primary.opacity(0.03), in: RoundedRectangle(cornerRadius: 12, style: .continuous))
                .overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).stroke(open == i ? accBlue.opacity(0.3) : Color.primary.opacity(0.08), lineWidth: 1))
            }
        }.frame(width: 330)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17