Skip to content
Invoice Table preview
Rendered from the SwiftUI source on this page.

Invoice Table

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

Line items with hours and amounts plus a bold total row.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

TableInvoice.swift
// Invoice Table · syxUI · https://syxui.dev/components/table-invoice
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func tblCard(_ w: CGFloat) -> some View {
        self.frame(width: w)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 18, style: .continuous))
            .clipShape(RoundedRectangle(cornerRadius: 18, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 18, style: .continuous).stroke(Color.primary.opacity(0.08), lineWidth: 1))
            .shadow(color: .black.opacity(0.04), radius: 10, x: 0, y: 4)
    }
}

/// Invoice - line items with hours and amount, bold total row at the foot.
struct TableInvoice: View {
    let rows: [(String, String, String)] = [
        ("Design work", "12 h", "$1,440"), ("Development", "30 h", "$4,500"), ("QA testing", "8 h", "$720"),
    ]
    var body: some View {
        VStack(spacing: 0) {
            HStack {
                Text("Item").frame(maxWidth: .infinity, alignment: .leading)
                Text("Hours").frame(width: 56, alignment: .trailing)
                Text("Amount").frame(width: 76, alignment: .trailing)
            }.font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary).padding(.horizontal, 16).padding(.vertical, 10)
            Divider()
            ForEach(Array(rows.enumerated()), id: \.offset) { _, r in
                HStack {
                    Text(r.0).font(.system(size: 14, weight: .medium)).frame(maxWidth: .infinity, alignment: .leading)
                    Text(r.1).font(.system(size: 14).monospacedDigit()).foregroundStyle(.secondary).frame(width: 56, alignment: .trailing)
                    Text(r.2).font(.system(size: 14, weight: .medium).monospacedDigit()).frame(width: 76, alignment: .trailing)
                }.padding(.horizontal, 16).padding(.vertical, 11)
            }
            Divider()
            HStack {
                Text("Total").font(.system(size: 15, weight: .bold)).frame(maxWidth: .infinity, alignment: .leading)
                Text("$6,660").font(.system(size: 15, weight: .bold).monospacedDigit())
            }.padding(.horizontal, 16).padding(.vertical, 12).background(Color.primary.opacity(0.03))
        }
        .tblCard(330)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17