SwiftUICalendar
  • July 2, 2025

Installation


Swift Package Manager

  • From url : https://github.com/GGJJack/SwiftUICalendar

or

  • Package.swift

.package(name: “SwiftUICalendar”, url: “https://github.com/GGJJack/SwiftUICalendar”, from: “0.1.14”)

CocoaPods

pod ‘SwiftUICalendar’

import

import SwiftUICalendar

Features


  • Infinite scroll
  • Support horizontal and vertical scroll
  • Full custom calendar cell
  • Pager lock
  • Starting the week with Sunday or Monday

Example


Basic

CalendarView() { date in
Text(“\(date.day)”)
}

Basic use

Basic Use

Show example code

Embed Header

Basic Use

Calendar scroll

Basic Use

Information

Basic Use

Selection

Basic Use

Information + Selection

Basic Use

Date change detection

CalendarView(controller) { date in
….
}
.onChange(of: controller.yearMonth) { yearMonth in
print(yearMonth)
}

Start with Monday

Basic Use

Struct


CalendarView

public struct CalendarView<CalendarCell: View, HeaderCell: View>: View {
public init(
_ controller: CalendarController = CalendarController(),
startWithMonday: Bool = false,
@ViewBuilder component: @escaping (YearMonthDay) -> CalendarCell
) {

}
public init(
_ controller: CalendarController = CalendarController(),
startWithMonday: Bool = false,
headerSize: HeaderSize = .fixHeight(40),
@ViewBuilder header: @escaping (Week) -> HeaderCell,
@ViewBuilder component: @escaping (YearMonthDay) -> CalendarCell
) {

}


}

HeaderSize

public enum HeaderSize {
case zero
case ratio
case fixHeight(CGFloat)
}

CalendarController

public class CalendarController: ObservableObject {
public init(
_ yearMonth: YearMonth = .current,
orientation: Orientation = .horizontal,
isLocked: Bool = false
)


}

var verticalController = CalendarController(
YearMonth.current,
orientation: .vertical,
isLocked: true
)

var controller = CalendarController()

// Scroll with animate
controller.scrollTo(year: 1991, month: 2, isAnimate: true)

// Scroll without animate
controller.scrollTo(YearMonth.current, isAnimate: false)

// Lock Pager
controller.isLocked = true

YearMonth

public struct YearMonth: Equatable {
public let year: Int
public let month: Int

public init(year: Int, month: Int) { … }


}

let date = YearMonth(year: 2021, month: 10)
let now = YearMonth.current // Now

print(date.monthShortString) // Oct // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

let nextMonth = date.addMonth(value: 1) // {year: 2021, month: 11}

let diff = nextMonth.diffMonth(value: date) // 2021/11 – 2021/10 = 1

let components: DateComponents = nextMonth.toDateComponents()

YearMonthDay

public struct YearMonthDay: Equatable {
public let year: Int
public let month: Int
public let day: Int
public let isFocusYearMonth: Bool?

public init(year: Int, month: Int, day: Int) { … }

public init(year: Int, month: Int, day: Int, isFocusYearMonth: Bool) { … }


}

let date = YearMonthDay(year: 2021, month: 10, day: 26)
let now = YearMonthDay.current

let isToday = now.isToday // true

let dayOfWeek: Week = date.dayOfWeek // Tue // Sun, Mon, Tue, Wed, Thu, Fri, Sat

let toDate = date.date! // { 2021/10/26 }

let components: DateComponents = date.toDateComponents()

let tomorrow = date.addDay(value: 1) // {year: 2021, month: 10, day: 27}

let diff = tomorrow.diffDay(value: date) // 2021/10/27 – 2021/10/26 = 1

Week

public enum Week: Int, CaseIterable {
case sun = 0
case mon = 1
case tue = 2
case wed = 3
case thu = 4
case fri = 5
case sat = 6

public var shortString: String // Sun, Mon, Tue, Wed, Thu, Fri, Sat
}

GitHub


View Github

#ios #swift
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...