YACalendar is a highly customizable iOS calendar that’s easy to integrate into your application. Currently, it supports year and month views with vertical and horizontal scrolling. Our solution optimized for all iPhone screens, so it will display correctly on old devices like the iPhone 5 as well as on the newest iPhone models. YACalendar is constantly evolving and aims to become a one-size-fits-all solution. We’re planning to add event management functionality and the ability to attach notes, links, and documents to events.
YACalendar | |
---|---|
✅ | Year view with 2 or 3 columns and month view |
✅ | Portrait and landscape modes |
✅ | Vertical and horizontal scrolling |
✅ | Paging |
✅ | Markers for current and selected dates |
✅ | Markers for past and future events |
✅ | Ability to set the start of the week to Monday or Sunday |
✅ | Weekend view |
✅ | Selection of one, multiple, or a range of days |
Take a look at an example project here
- Swift 5.0
- Xcode 11.2
- iOS 10.0+
To install YACalendar via CocoaPods, add the following lines to your Podfile:
use_frameworks!
pod 'YACalendar'
Then make sure to add this line to your code:
import YACalendar
- Create a calendar view instance and add it to the view hierarchy.
let calendarView = CalendarView(frame: frame)
view.addSubview(calendarView)
NOTE: You can use an interface builder for creating a calendar view. Here’s an example.
- Create a calendar. If you want to change the first day of the week, change the
firstWeekday
property.
let calendar = Calendar.current
calendar.firstWeekday = 2 // 1 - Sunday, 2 - Monday
- Specify the calendar grid type and scroll direction.
calendarView.grid.calendarType = .oneOnOne
calendarView.grid.scrollDirection = .vertical
- Create the calendar data object, which contains the calendar itself, the start date, and the end date. Set it to the
data
property of the calendar view. All days will be displayed according to the specified calendar and within the range of the start and end dates.
calendarView.data = CalendarData(calendar: calendar, startDate: startDate, endDate: endDate)
NOTE: After setting the data
property, the calendar will be redrawn.
Month view with vertical and horizontal scrolling:
let calendarView = CalendarView(frame: frame)
calendarView.grid.calendarType = .onOnOne
calendarView.data = CalendarData()
Year view with a 3×4 grid for portrait orientation and a 5×2 grid for landscape orientation:
var calendarView = CalendarView(frame: frame)
calendarView.grid.calendarType = .threeOnFour
calendarView.data = CalendarData()
Year view with a 2×3 grid for portrait orientation and a 3×1 grid for landscape orientation:
let calendarView = CalendarView(frame: frame)
calendarView.grid.calendarType = .twoOnThree
calendarView.data = CalendarData()
These settings can be configured directly on the CalendarView
.
Property | Description |
---|---|
currentDate: Bool | The date to which the calendar should scroll |
selectionType: SelectionType | Selection type (for selecting dates): one, many, range |
Method | Description |
---|---|
func scroll(to date: Date) | Scroll to the month with the specified date. |
func selectDay(with date: Date) | Select/deselect a specific day. Use this method for selecting/deselecting a single day. |
func selectDays(with dates: [Date]) | Select/deselect specified days. Use this method for selecting/deselecting multiple days. |
func selectRange(with startDay: Date, endDate: Date) | Select a range of days within the start and end dates. |
func setEvents(_ events: [CalendarEvent]) | Set events to the dates specified in the event. |
func disableDays(with dates: [Date]) | Disable specified days. |
If you want to change the font, color, or other UI properties of one of these elements, you must override the corresponding element config.
For example, to change the text color for days:
- Inherit
DayConfig
and override the method.
class MyDayConfig: DayConfig {
override func textColor(for state: DayState, indicator: DayIndicator) -> UIColor {
return .black
}
}
- Set config to the calendar.
calendarView.config.day = MyDayConfig()
You can set these settings by calling calendar.grid
Property | Description |
---|---|
calendarType: CalendarType | Grid representation of months. Possible values: oneOnOne, twoOnThree, threeOnFour |
scrollDirection: ScrollDirection | Set vertical or horizontal scrolling direction |
We have far-reaching plans to improve YACalendar. We want to add:
- Event view (creating, management, recurring events)
- Appointment scheduling view
- Dark mode
Version 1.0
- Release version.
YACalendar
is released under an MIT License. See LICENSE
for details.