CalendarView

1.0.3

Build a Calendar By Pure SwiftUI
iletai/SwiftUICalendarView

What's New

1.0.3

2023-12-25T06:13:15Z

What's Changed

Full Changelog: 1.0.2...1.0.3

SwiftUICalendarView

Build a Calendar By Pure SwiftUI with SwiftDate Library for calculator date.

SwiftUICalendarView

Swift Platform License Build Project codecov

SwiftUICalendarView is a Swift Package for building and displaying a simple calendar interface in SwiftUI. This library provides an easy way to integrate a calendar into your app.

Installation

Swift Package Manager

To integrate SwiftUICalendarView into your project, add the GitHub URL to the dependencies section in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/iletai/SwiftUICalendarView.git", from: "1.0.0"),
],
targets: [
    .target(name: "YourTarget", dependencies: ["CalendarView"]),
]

Calendar Mode Support:

Month Mode Year Mode Week Mode
image image image

Usable Example Calendar View

import SwiftUI
import CalendarView
import SwiftDate

struct ContentView: View {
    @State var isShowHeader = false
    @State var isShowDateOut = false
    @State var firstWeekDate = 1
    @State var viewMode = CalendarViewMode.year
    @State private var selectedDate = Date()
    @State var listSelectedDate = [Date]()

    var body: some View {
        VStack {
            CalendarView(
                date: selectedDate
                , dateView: { date in
                    VStack {
                        Text(date.dayName)
                            .font(.footnote)
                            .fontWeight(.semibold)
                            .foregroundColor(
                                Calendar.current.isDateInWeekend(date) ? .red : .black
                            )
                    }
                    .frame(maxWidth: .infinity)
                    .frame(height: 30)
                    .background(listSelectedDate.contains(date) ? .cyan : .clear)
                }, headerView: { date in
                    VStack {
                        Text(date.weekDayShortName)
                            .font(.footnote)
                            .fontWeight(.bold)
                            .foregroundColor(
                                Calendar.current.isDateInWeekend(date) ? .red : .black
                            )
                    }
                }, dateOutView: { date in
                    Text(DateFormatter.day.string(from: date))
                        .font(.footnote)
                        .foregroundColor(.gray)
                },
                onSelectedDate: onSelectedDate
            )

Customizing the Interface

You can customize the calendar's interface using properties like accentColor, selectedDateColor, and disabledDateColor,...

            .enableHeader(isShowHeader)
            .enableDateOut(isShowDateOut)
            .firstWeekDay(firstWeekDate)
            .calendarLocate(locale: Locales.vietnamese.toLocale())
            .enablePinedView(.sectionHeaders)
            .setViewMode(viewMode)
            .rowsSpacing(0)
            .columnSpacing(0)
            .backgroundCalendar(.visible(20, .gray.opacity(0.3)))
            .onDraggingEnded {
                selectedDate = selectedDate.nextWeekday(.friday)
            }

Contribution

If you find a bug or have a way to improve the library, create an Issue or propose a Pull Request. We welcome contributions from the community.

License

SwiftUICalendarView is released under the MIT License. See details in LICENSE.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sat Dec 21 2024 15:10:11 GMT-1000 (Hawaii-Aleutian Standard Time)