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

Leaderboard

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

A ranked leaderboard with avatars and scores.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

LeaderboardCard.swift
// Leaderboard · syxUI · https://syxui.dev/components/card-leaderboard
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

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

// Leaderboard card
struct LeaderboardCard: View {
    let rows = [("1", "person_5", "Sarah M.", "2,840"), ("2", "person_2", "James W.", "2,610"), ("3", "person_3", "Mia C.", "2,390")]
    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: 15, weight: .bold)).foregroundStyle(i == 0 ? Color(red: 0.98, green: 0.72, blue: 0.10) : .secondary).frame(width: 20)
                    Image(r.1).resizable().scaledToFill().frame(width: 36, height: 36).clipShape(Circle())
                    Text(r.2).font(.system(size: 15, weight: .medium))
                    Spacer()
                    Text(r.3).font(.system(size: 15, weight: .semibold))
                    Image(systemName: "star.fill").font(.system(size: 11)).foregroundStyle(.orange)
                }.padding(.vertical, 9)
                if i < 2 { Divider() }
            }
        }.formaCard(14).frame(width: 300)
    }
}
iOS 17 · 3 dependencies

Dependencies

SwiftUI
  • person_2 (image asset)
  • person_3 (image asset)
  • person_5 (image asset)

Requires iOS 17