Skip to content
Cost Comparison preview
Rendered from the SwiftUI source on this page.

Cost Comparison

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

A cost breakdown with a highlighted plan column and inline savings.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

TableCost.swift
// Cost Comparison · syxUI · https://syxui.dev/components/table-cost
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let tblBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

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)
    }
}

/// Cost comparison with a highlighted "premium" column and inline savings (ASOS).
struct TableCost: View {
    let rows: [(String, String, String, String)] = [
        ("1 order", "$45", "$99", ""), ("5 orders", "$225", "$99", "Save $126"),
        ("10 orders", "$450", "$99", "Save $351"), ("20 orders", "$900", "$99", "Save $801"),
    ]
    var body: some View {
        VStack(spacing: 0) {
            HStack(spacing: 0) {
                Text("Orders / yr").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary)
                    .frame(maxWidth: .infinity, alignment: .leading).padding(.leading, 16)
                Text("Standard").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary).frame(width: 70)
                Text("Premium").font(.system(size: 11, weight: .bold)).foregroundStyle(tblBlue)
                    .frame(width: 92, height: 42).background(tblBlue.opacity(0.08))
            }
            Divider()
            ForEach(Array(rows.enumerated()), id: \.offset) { i, r in
                HStack(spacing: 0) {
                    Text(r.0).font(.system(size: 14, weight: .medium)).frame(maxWidth: .infinity, alignment: .leading).padding(.leading, 16)
                    Text(r.1).font(.system(size: 14).monospacedDigit()).foregroundStyle(.secondary).frame(width: 70)
                    VStack(spacing: 1) {
                        Text(r.2).font(.system(size: 14, weight: .bold).monospacedDigit())
                        if !r.3.isEmpty { Text(r.3).font(.system(size: 9, weight: .bold)).foregroundStyle(tblBlue) }
                    }.frame(width: 92, height: 54).background(tblBlue.opacity(0.08))
                }
                if i < rows.count - 1 { Divider() }
            }
        }
        .tblCard(320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17