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

Timeline Bars

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

A Gantt-style project timeline.

Charts · SwiftUI · iOS 17

  • charts
  • swiftui

The actual source

TimelineBars.swift
// Timeline Bars · syxUI · https://syxui.dev/components/chart2-timeline
// 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)
    }
}

// Timeline / schedule bars
struct TimelineBars: View {
    let rows: [(String, Double, Double, Color)] = [("Design", 0.0, 0.5, Color(red: 0.0, green: 0.47, blue: 1.0)), ("Build", 0.3, 0.85, Color(red: 0.55, green: 0.40, blue: 0.90)), ("Test", 0.6, 1.0, Color(red: 0.16, green: 0.66, blue: 0.40)), ("Launch", 0.9, 1.0, Color(red: 0.98, green: 0.55, blue: 0.10))]
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Project timeline").font(.system(size: 15, weight: .semibold))
            ForEach(Array(rows.enumerated()), id: \.offset) { _, r in
                HStack(spacing: 10) {
                    Text(r.0).font(.system(size: 12, weight: .medium)).frame(width: 48, alignment: .leading)
                    GeometryReader { g in
                        Capsule().fill(r.3).frame(width: g.size.width * (r.2 - r.1), height: 12).offset(x: g.size.width * r.1)
                    }.frame(height: 12)
                }
            }
        }.formaCard().frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17