CalendarView Documentation

repository·main·Indexed 20 days ago

https://github.com/mijick/calendarview

A SwiftUI library for creating customizable calendars using a builder pattern. Features include the MCalendarView constructor for date and date range selection, a configBuilder for appearance and behavior customization, and protocol-based customization for WeekdaysView, WeekdayLabel, MonthLabel, and DayView.

Tokens
769
Snippets
4
Records
5
Agent score
19%

What's inside CalendarView

  1. Install CalendarView via CocoaPods

    main

    To install using CocoaPods, follow these steps:

    1. Ensure CocoaPods 1.10.0 or later is installed.
    2. Initialize CocoaPods in your project directory: pod init.
    3. Add the dependency to your Podfile: pod 'MijickCalendarView'
    4. Run pod install to generate the .xcworkspace file.
    5. Open and use the .xcworkspace file for your project.
    pod init
    pod 'MijickCalendarView'
    pod install
  2. Install CalendarView via Swift Package Manager

    main

    Add CalendarView as a dependency in your Package.swift file using the following URL and branch:

    dependencies: [
        .package(url: "https://github.com/Mijick/CalendarView.git", branch("main"))
    ]
  3. Customize MCalendarView using configBuilder

    main

    You can customize the appearance and behavior of MCalendarView by providing a trailing closure to the initializer. This closure uses a configBuilder to apply various configurations such as custom day views, setting the first weekday of the week, and defining custom weekdays views.

    struct ContentView: View {
        @State private var selectedDate: Date? = nil
        @State private var selectedRange: MDateRange? = .init()
    
        var body: some View {
            MCalendarView(selectedDate: nil, selectedRange: $selectedRange) {
                $0
                    (...)
                    .dayView(NewDayView.init)
                    .firstWeekday(.wednesday)
                    .monthLabelToDaysDistance(12)
                    .weekdaysView(NewWeekdaysView.init)
                    (...)
            }
        }
    }
  4. Initialize MCalendarView

    main

    To declare a basic calendar, use the MCalendarView constructor. You can pass a binding to a single selectedDate or a binding to an MDateRange to manage date selection.

    struct ContentView: View {
        @State private var selectedDate: Date? = nil
        @State private var selectedRange: MDateRange? = .init()
    
        var body: some View {
            MCalendarView(selectedDate: $selectedDate, selectedRange: $selectedRange)
        }
    }