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

Activity Rings

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

A hand-built activity rings — self-contained SwiftUI, no chart framework, restyles from one accent.

Charts · SwiftUI · iOS 17

  • charts
  • swiftui

The actual source

CardHeader.swift
// Activity Rings · syxUI · https://syxui.dev/components/chart-rings
// 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)
    }
}

struct CardHeader: View {
    let label: String; let value: String; var trend: String? = nil
    var body: some View {
        HStack(alignment: .firstTextBaseline) {
            VStack(alignment: .leading, spacing: 3) {
                Text(label).font(.system(size: 13, weight: .medium)).foregroundStyle(.secondary)
                Text(value).font(.system(size: 26, weight: .bold))
            }
            Spacer()
            if let trend {
                Text(trend).font(.system(size: 12, weight: .semibold))
                    .padding(.horizontal, 8).padding(.vertical, 3)
                    .background(Color.primary.opacity(0.06), in: Capsule())
            }
        }
    }
}
// 6. Activity rings
struct ActivityRingsCard: View {
    let rings: [(Double, Double)] = [(0.78, 1.0), (0.55, 0.7), (0.9, 0.45)]
    var body: some View {
        HStack(spacing: 18) {
            ZStack {
                ForEach(rings.indices, id: \.self) { i in
                    Circle().stroke(Color.primary.opacity(0.10), lineWidth: 11).padding(CGFloat(i) * 15)
                    Circle().trim(from: 0, to: rings[i].0)
                        .stroke(Color.primary.opacity(rings[i].1), style: .init(lineWidth: 11, lineCap: .round))
                        .rotationEffect(.degrees(-90)).padding(CGFloat(i) * 15)
                }
            }
            .frame(width: 116, height: 116)
            VStack(alignment: .leading, spacing: 10) {
                ForEach([("Move", "350 kcal"), ("Exercise", "24 min"), ("Stand", "9 hr")].indices, id: \.self) { i in
                    let d = [("Move", "350 kcal"), ("Exercise", "24 min"), ("Stand", "9 hr")][i]
                    VStack(alignment: .leading, spacing: 1) {
                        Text(d.0.uppercased()).font(.system(size: 10, weight: .semibold)).foregroundStyle(.secondary)
                        Text(d.1).font(.system(size: 17, weight: .bold))
                    }
                }
            }
            Spacer()
        }
        .formaCard()
    }
}
iOS 17 · 2 dependencies

Dependencies

SwiftUI
  • formaCard
  • CardHeader

Requires iOS 17