
Leaderboard
From syxUI — written for both platforms, not translated between them.
A ranked leaderboard with avatars, scores and top-three crowns.
Cards · SwiftUI · iOS 17
- cards
- swiftui
The actual source
TableLeaderboard.swift
// Leaderboard · syxUI · https://syxui.dev/components/table-leaderboard
// 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)
}
}
/// Leaderboard - rank, initial avatar, name, score; top three get a crown.
struct TableLeaderboard: View {
let rows: [(Int, String, String, String, Color)] = [
(1, "AK", "Alex Kim", "12,480", Color(red: 0.85, green: 0.65, blue: 0.13)),
(2, "MR", "Maria Ruiz", "11,920", Color(red: 0.58, green: 0.60, blue: 0.64)),
(3, "JC", "James Cho", "10,540", Color(red: 0.72, green: 0.45, blue: 0.20)),
(4, "SP", "Sara Patel", "9,310", Color(red: 0.45, green: 0.50, blue: 0.60)),
(5, "TN", "Tom Nguyen", "8,760", Color(red: 0.45, green: 0.50, blue: 0.60)),
]
var body: some View {
VStack(spacing: 0) {
ForEach(Array(rows.enumerated()), id: \.offset) { i, r in
HStack(spacing: 12) {
Text("\(r.0)").font(.system(size: 14, weight: .bold).monospacedDigit()).foregroundStyle(r.0 <= 3 ? Color.primary : Color.secondary).frame(width: 20)
ZStack {
Circle().fill(r.4.opacity(0.18)).frame(width: 34, height: 34)
Text(r.1).font(.system(size: 12, weight: .bold)).foregroundStyle(r.4)
}
Text(r.2).font(.system(size: 15, weight: .medium)).frame(maxWidth: .infinity, alignment: .leading)
if r.0 <= 3 { Image(systemName: "crown.fill").font(.system(size: 11)).foregroundStyle(r.4) }
Text(r.3).font(.system(size: 15, weight: .bold).monospacedDigit())
}
.padding(.horizontal, 16).padding(.vertical, 9)
if i < rows.count - 1 { Divider().padding(.leading, 60) }
}
}
.padding(.vertical, 6)
.tblCard(330)
}
}
iOS 17 · No dependencies
Dependencies
- SwiftUI
- No external dependencies
Requires iOS 17


