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

Goal Progress

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

Labeled goal progress bars for daily targets.

Charts · SwiftUI · iOS 17

  • charts
  • swiftui

The actual source

GoalProgressBars.swift
// Goal Progress · syxUI · https://syxui.dev/components/chart2-goal-bars
// 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)
    }
}

// Goal progress bars (MacroFactor)
struct GoalProgressBars: View {
    let goals: [(String, String, Double, Color)] = [("Calories", "1,840 / 2,200", 0.83, Color(red: 0.98, green: 0.55, blue: 0.10)), ("Protein", "96 / 140 g", 0.68, Color(red: 0.0, green: 0.47, blue: 1.0)), ("Carbs", "180 / 250 g", 0.72, Color(red: 0.16, green: 0.66, blue: 0.40)), ("Fat", "48 / 70 g", 0.68, Color(red: 0.55, green: 0.40, blue: 0.90))]
    var body: some View {
        VStack(alignment: .leading, spacing: 14) {
            Text("Today's goals").font(.system(size: 15, weight: .semibold))
            ForEach(Array(goals.enumerated()), id: \.offset) { _, g in
                VStack(alignment: .leading, spacing: 5) {
                    HStack { Text(g.0).font(.system(size: 13, weight: .medium)); Spacer(); Text(g.1).font(.system(size: 12)).foregroundStyle(.secondary) }
                    GeometryReader { geo in
                        ZStack(alignment: .leading) {
                            Capsule().fill(Color.primary.opacity(0.08)).frame(height: 7)
                            Capsule().fill(g.3).frame(width: geo.size.width * g.2, height: 7)
                        }
                    }.frame(height: 7)
                }
            }
        }.formaCard().frame(width: 300)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17