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

Mini Calendar

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

A compact inline calendar.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

PickerMiniCalendar.swift
// Mini Calendar · syxUI · https://syxui.dev/components/picker-mini
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let pkBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

func weekdays() -> some View { HStack(spacing: 0) { ForEach(Array(["S", "M", "T", "W", "T", "F", "S"].enumerated()), id: \.offset) { _, d in Text(d).font(.system(size: 11, weight: .medium)).foregroundStyle(.secondary).frame(maxWidth: .infinity) } } }

func monthGrid(_ days: Int, _ lead: Int, _ selected: Set<Int>, _ accent: Color, range: Set<Int> = []) -> some View {
    LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 7), spacing: 6) {
        ForEach(Array(0..<lead), id: \.self) { _ in Color.clear.frame(height: 30) }
        ForEach(1...days, id: \.self) { d in
            Text("\(d)").font(.system(size: 13, weight: selected.contains(d) ? .bold : .regular)).foregroundStyle(selected.contains(d) ? .white : (range.contains(d) ? accent : .primary))
                .frame(width: 30, height: 30)
                .background { if selected.contains(d) { Circle().fill(accent) } else if range.contains(d) { Circle().fill(accent.opacity(0.14)) } }
        }
    }
}

struct PickerMiniCalendar: View { var body: some View { VStack(spacing: 8) { Text("July").font(.system(size: 14, weight: .semibold)); weekdays(); monthGrid(31, 3, [15], pkBlue) }.padding(12).frame(width: 250).background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 14, style: .continuous)).overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).stroke(Color.primary.opacity(0.08))) } }
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17