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...
TextView

Download File -> Swift Packages -> Add Package Dependency... Select your project Enter https://github.com/kenmueller/TextView for the package repository URL Select Branch: master Click Finish ...

KeyboardAvoider

 

Focuser

Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS ...

OmenTextField

A better TextField for SwiftUI. A growing, multiline, auto-focusable TextField supporting bindable focus. This has been pulled out of my ...

iPhoneNumberField ☎️

Format phone numbers as they're typed—entirely in SwiftUI. 📱   Get Started | Examples | Customize | Features | Install | Pricing And it's as easy as