Skip to content
Two-Month Range preview
Rendered from the SwiftUI source on this page.

Two-Month Range

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

A two-month date-range picker.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

PickerRangeTwoMonths.swift
// Two-Month Range · syxUI · https://syxui.dev/components/picker-range-2
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let pkPurple = Color(red: 0.55, green: 0.40, blue: 0.90)

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

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 PickerRangeTwoMonths: View { var body: some View { VStack(spacing: 16) { HStack { Text("Apr 28 – May 4").font(.system(size: 16, weight: .semibold)); Spacer(); Text("Apply").font(.system(size: 14, weight: .semibold)).foregroundStyle(pkPurple) }; VStack(spacing: 8) { Text("April 2026").font(.system(size: 13, weight: .semibold)); monthGrid(30, 3, [28], pkPurple, range: [29, 30]) }; VStack(spacing: 8) { Text("May 2026").font(.system(size: 13, weight: .semibold)); monthGrid(31, 5, [4], pkPurple, range: [1, 2, 3]) } }.formaCard().frame(width: 300) } }
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17