Skip to content
Markets List preview
Rendered from the SwiftUI source on this page.

Markets List

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

Index rows with a badge, last price and colored percent change.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

TableMarkets.swift
// Markets List · syxUI · https://syxui.dev/components/table-markets
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let tblGreen = Color(red: 0.13, green: 0.62, blue: 0.32)

let tblRed = Color(red: 0.86, green: 0.24, blue: 0.21)

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

func tblBadge(_ initials: String, _ color: Color) -> some View {
    Text(initials).font(.system(size: 10, weight: .bold)).foregroundStyle(.white)
        .frame(width: 26, height: 26).background(Circle().fill(color))
}

/// Markets list - index badge, name, last price, colored percent change (Fidelity).
struct TableMarkets: View {
    let rows: [(String, Color, String, String, String, Bool)] = [
        ("US", Color(red: 0.20, green: 0.40, blue: 0.75), "S&P 500", "5,646.92", "+0.42%", true),
        ("UK", Color(red: 0.78, green: 0.15, blue: 0.20), "FTSE 100", "8,320.11", "−0.18%", false),
        ("DE", Color(red: 0.12, green: 0.12, blue: 0.14), "DAX", "18,720.30", "+1.02%", true),
        ("JP", Color(red: 0.85, green: 0.30, blue: 0.35), "Nikkei", "38,062.67", "−0.34%", false),
        ("HK", Color(red: 0.90, green: 0.45, blue: 0.20), "Hang Seng", "17,940.68", "+2.10%", true),
    ]
    var body: some View {
        VStack(spacing: 0) {
            ForEach(Array(rows.enumerated()), id: \.offset) { i, r in
                HStack(spacing: 12) {
                    tblBadge(r.0, r.1)
                    Text(r.2).font(.system(size: 15, weight: .medium)).frame(maxWidth: .infinity, alignment: .leading)
                    Text(r.3).font(.system(size: 14).monospacedDigit()).foregroundStyle(.secondary)
                    Text(r.4).font(.system(size: 13, weight: .semibold).monospacedDigit()).foregroundStyle(r.5 ? tblGreen : tblRed).frame(width: 60, alignment: .trailing)
                }
                .padding(.horizontal, 16).padding(.vertical, 11)
                if i < rows.count - 1 { Divider().padding(.leading, 54) }
            }
        }
        .padding(.vertical, 4)
        .tblCard(340)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17