Skip to content
Icon Rows preview
Rendered from the SwiftUI source on this page.

Icon Rows

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

Icon-led rows that expand to a description.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccIconRows.swift
// Icon Rows · syxUI · https://syxui.dev/components/acc-icon-rows
// 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)
    }
}

// Icon-led rows accordion
struct AccIconRows: View {
    @State private var open = 0
    let items = [("bell.fill", "Notifications", "Manage push, email and in-app alerts across your devices."),
                         ("lock.fill", "Privacy", "Control who can see your activity."),
                         ("creditcard.fill", "Billing", "Update payment methods and view invoices.")]
    var body: some View {
        VStack(spacing: 0) {
            ForEach(Array(items.enumerated()), id: \.offset) { i, it in
                HStack(spacing: 12) {
                    Image(systemName: it.0).font(.system(size: 15)).foregroundStyle(accBlue).frame(width: 26)
                    Text(it.1).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, 13).contentShape(Rectangle()).onTapGesture { open = open == i ? -1 : i }
                if open == i { Text(it.2).font(.system(size: 13)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding(.leading, 38).padding(.bottom, 13) }
                if i < items.count - 1 { Divider() }
            }
        }.formaCard(16).frame(width: 340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17