{"id":18993423,"url":"https://github.com/mmick66/calendarview","last_synced_at":"2025-05-16T16:01:33.421Z","repository":{"id":37851887,"uuid":"55976038","full_name":"mmick66/CalendarView","owner":"mmick66","description":"An Easy to Use Calendar for iOS (Swift 5.0)","archived":false,"fork":false,"pushed_at":"2023-11-16T02:22:54.000Z","size":2309,"stargazers_count":608,"open_issues_count":31,"forks_count":115,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-12T14:18:44.479Z","etag":null,"topics":["calendar","calendar-component","calendar-view","calendarview","date","date-picker","date-time","datepicker","datetime","swift","utc"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmick66.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-04-11T13:47:07.000Z","updated_at":"2025-03-29T04:29:57.000Z","dependencies_parsed_at":"2024-01-05T20:19:51.434Z","dependency_job_id":"f0da8189-6382-4796-9cf8-367c0d5ea81e","html_url":"https://github.com/mmick66/CalendarView","commit_stats":{"total_commits":316,"total_committers":33,"mean_commits":9.575757575757576,"dds":0.5253164556962026,"last_synced_commit":"2e677a018968a8b6deb6828d8a2f2e8d28e6b1f1"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmick66%2FCalendarView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmick66%2FCalendarView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmick66%2FCalendarView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmick66%2FCalendarView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmick66","download_url":"https://codeload.github.com/mmick66/CalendarView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578876,"owners_count":21127714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calendar","calendar-component","calendar-view","calendarview","date","date-picker","date-time","datepicker","datetime","swift","utc"],"created_at":"2024-11-08T17:21:17.233Z","updated_at":"2025-04-12T14:18:53.897Z","avatar_url":"https://github.com/mmick66.png","language":"Swift","readme":"![Karmadust](https://github.com/Tobaloidee/CalendarView/blob/master/Assets/logotype.png)\r\n\r\n[![Language](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://swift.org)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n[![CocoaPods](https://img.shields.io/cocoapods/v/KDCalendar.svg?style=flat)](https://cocoapods.org/pods/KDCalendar)\r\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/vsouza/awesome-ios)\r\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\r\n\r\nThis is an easy to use, \"just drag and drop it in your code\" type of calendar for iOS. It supports both **vertical** and **horizontal** scrolling, as well as native **calendar events**.\r\n\r\n![Calendar Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/screenshots.png)\r\n\r\n# Requirements\r\n\r\n* iOS 8.0+\r\n* XCode 9.0+\r\n* Swift 4.2\r\n\r\n# Installation\r\n\r\n#### CocoaPods\r\n\r\n```\r\npod 'KDCalendar', '~\u003e 1.8.9'\r\n```\r\n\r\n#### Carthage\r\n\r\nAdd this to your Cartfile, and then run `carthage update`:\r\n```\r\ngithub \"mmick66/CalendarView\" \"master\"\r\n```\r\n\r\n#### Swift Package Manager\r\n\r\nGo to Project -\u003e Swift Packages and add the repository:\r\n```\r\nhttps://github.com/mmick66/CalendarView.git\r\n```\r\n\r\n\r\nAdd this to your Package.swift:\r\n```\r\ndependencies: [\r\n    .Package(url: \"https://github.com/mmick66/CalendarView\")\r\n]\r\n```\r\n\r\n\r\n#### Manual\r\n\r\nJust the files from the **CalendarView/** subfolder to your project.\r\n\r\n# Setup\r\n\r\nThe calendar is a `UIView` and can be added either programmatically or via a XIB/Storyboard. **If doing the latter, make sure that the Module is selected to be 'KDCalendar'**.\r\n\r\n![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screenshot.png)\r\n\r\nIt needs a delegate and data source that comply with:\r\n\r\n```Swift\r\nprotocol CalendarViewDataSource {\r\n    func startDate() -\u003e NSDate // UTC Date\r\n    func endDate() -\u003e NSDate   // UTC Date\r\n}\r\nprotocol CalendarViewDelegate {\r\n    func calendar(_ calendar : CalendarView, canSelectDate date : Date) -\u003e Bool /* optional */\r\n    func calendar(_ calendar : CalendarView, didScrollToMonth date : Date) -\u003e Void\r\n    func calendar(_ calendar : CalendarView, didSelectDate date : Date, withEvents events: [CalendarEvent]) -\u003e Void\r\n    func calendar(_ calendar : CalendarView, didDeselectDate date : Date) -\u003e Void /* optional */\r\n    func calendar(_ calendar : CalendarView, didLongPressDate date : Date, withEvents events: [CalendarEvent]?) -\u003e Void /* optional */\r\n}\r\n```\r\n\r\nThe data source will provide the **start date** and the **end date** of the calendar. The methods have a default implementation that will return `Date()` resulting in a single-page calendar displaying the current month.\r\n\r\nThe delegate responds to events such as scrolling and the selection of specific dates.\r\n\r\nNote: The dates should be in UTC (same as GMT)\r\n\r\n# How to Use\r\n\r\nYou would want to implement the delegate functions inside your view controller as they appear in the example project.\r\n\r\nSay you want to be able to scroll 3 months into the past, then:\r\n\r\n```Swift\r\nfunc startDate() -\u003e Date {\r\n    var dateComponents = DateComponents()\r\n    dateComponents.month = -3\r\n    let today = Date()\r\n    let threeMonthsAgo = self.calendarView.calendar.date(byAdding: dateComponents, to: today)\r\n    return threeMonthsAgo\r\n}\r\n```\r\n\r\nYou probably still want the calendar to open in today's date, so in this case do:\r\n\r\n```Swift\r\noverride func viewDidAppear(_ animated: Bool) {\r\n    super.viewDidAppear(animated)\r\n    let today = Date()\r\n    self.calendarView.setDisplayDate(today, animated: false)        \r\n}\r\n```\r\n\r\nSay you want tomorrow to be selected for some reason:\r\n\r\n```Swift\r\n// can be in the viewDidAppear\r\nlet today = Date()\r\nif let tomorrow = self.calendarView.calendar.date(byAdding: tomorrowComponents, to: today) {\r\n  self.calendarView.selectDate(tomorrow)\r\n}\r\n```\r\n\r\n### Selecting and Deselecting Dates\r\n\r\nThe calendar supports the selection of multiple dates. You can select a date either by clicking on a cell or by selecting it programmatically as:\r\n\r\n```Swift\r\nself.calendarView.selectDate(date)\r\n```\r\n\r\nSimilarly you can deselect:\r\n\r\n```Swift\r\nself.calendarView.deselectDate(date)\r\n```\r\n\r\nYou can get all the dates that were selected, either manually or programatically using:\r\n\r\n```Swift\r\nself.calendarView.selectedDates\r\n```\r\n\r\n### Layout\r\n\r\nThe calendar supports two basic layouts. Set the `direction` property to `.horizontal` or `.vertical`:\r\n\r\n```Swift\r\ncalendarView.direction = .horizontal\r\n```\r\n\r\n\r\n### Styling\r\n\r\nThe look of this calendar can be set using the `CalendarView.Style` structure. There is an \"out of the box\" style that can be accessed statically through `CalendarView.Style.Default`. To change it, instantiatia a new Style object and set the variables in their desired value anywhere in your code.\r\n\r\n```Swift\r\noverride func viewDidLoad() {\r\n\r\n    super.viewDidLoad()\r\n\r\n    let myStyle = CalendarView.Style()\r\n    // set your values\r\n    calendarView.style = myStyle\r\n}\r\n```\r\n\r\nFor more information have a look at our [wiki](https://github.com/mmick66/CalendarView/wiki/Styling).\r\n#### Marking Weekends\r\n\r\nSome calendars will want to display weekends as special and mark them with a different text color. To do that, first set the marksWeekends variable on the calendarView itself and (optionally) define the color to use.\r\n\r\n```Swift\r\nCalendarView.Style.cellTextColorWeekend = UIColor.red\r\ncalendarView.marksWeekends = true\r\n```\r\n\r\n![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screen%20Shot%20Mark%20Weekends.png)\r\n\r\nThe `CellShape` will define whether the dates are displayed in a circle or square with bevel or not.\r\n\r\n#### Graying out days\r\n\r\nIf you want the days that lie outside of the rage set by `startDate` and `endDate`, you can set the color in:\r\n\r\n```Swift\r\nCalendarView.Style.cellColorOutOfRange = UIColor(white: 0.0, alpha: 0.5)\r\n```\r\n\r\n![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screen%20Shot%20Out%20of%20Range.png)\r\n\r\n#### First Day of the Week\r\n\r\nDepending on the culture weeks are considered to start either on a Monday or on a Sunday. To change the way the days are displayed use:\r\n\r\n```Swift\r\nCalendarView.Style.firstWeekday = .sunday\r\n```\r\n\r\n![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screen%20Shot%20First%20Day.png)\r\n\r\nThe calendar defaults to Monday which is standard in Europe.\r\n\r\n#### Set locale of calendar\r\n\r\nSet the locale for header labels of Weekdays and Month. Use:\r\n\r\n```Swift\r\nCalendarView.Style.locale = Locale(identifier: \"en_US\")\r\n```\r\n\r\n![IB Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screen%20Shots%20Locale.png)\r\n\r\nThe locale default is Locale.current of your device.\r\n\r\n#### Custom Headers\r\n\r\nDepending on the language, you might experience problems displaying the month strings in the header. There is however a method you can implement that will return any string you wish according to the date passed.\r\n\r\n```Swift\r\npublic protocol CalendarViewDataSource {\r\n    /* other methods */\r\n    func headerString(_ date: Date) -\u003e String?\r\n}\r\n```\r\n\r\n# Events\r\n\r\nThis component has the ability to sync events from the system's `EKEventStore`, which is shared with the native calendar provided in iOS. This ability is optional and (in order to keep the calendar's footprint low) needs to be activated seperatly via a custom flag in the build settings as shown below:\r\n\r\n![Events Screenshot](https://github.com/mmick66/CalendarView/blob/master/Assets/Screen%20Shot%20Add%20Events.png)\r\n\r\nIn the \"Build Settings,\" under the \"Swift Compiler - Custom Flags\" and \"Active Compilation Conditions,\" simply add the `KDCALENDAR_EVENT_MANAGER_ENABLED` flag for both debug and release. The events will be enabled.\r\n\r\n#### Loading Events\r\n\r\nTo load events from the system's calendar call the followint method:\r\n\r\n```Swift\r\nself.calendarView.loadEvents()\r\n```\r\n\r\nOptionally, a complete handler can be added in case an error is returned\r\n\r\n```Swift\r\nself.calendarView.loadEvents() { error in\r\n    if error != nil {\r\n        // handle error\r\n    }\r\n}\r\n```\r\n\r\nThe code will pop up an alert view to ask the user if he will allow this app to access the calendar. If access is granted we can pass the events to the `CalendarView`, otherwise we get a nil and notify the app about the denial.\r\n\r\n#### Creating (Adding) New Events\r\n\r\nThere is a function that allows you to add a new event in the calendar. It is currently restrictred to a single day (like the rest of the calendar)\r\n\r\n```Swift\r\nfunc addEvent(_ title: String, date: Date, duration hours: NSInteger = 1) -\u003e Bool\r\n```\r\n\r\nTo detect when the user wants to add a new date, the delegate can implement the `didLongPressDate` method will notify the controller for a long press and the `addEvent` function is usually used in conjuction with this delegate method.\r\n\r\nCurrently, the example implementation of this repo will open an alert view that will prompt the user for a title to the event and set it for the duration of an hour. Custom controls could be added to further refine the selection.\r\n\r\nAs with the loading of the events we need to give persmissions to the app.\r\n\r\n## About Dates\r\n\r\nCalculating dates can be somewhat complicated because while time is an absolute value, dates are a construct of culture: timezones are geopolitical areas and daylight savings times change according to government decision. The best way out of this is to calculate everything in UTC (same as GTM for what we are concerned) and so the `startDate` and `endDate` returned from the delegate should all be in UTC (+0000) time.\r\n\r\n## Help Needed\r\n\r\nIf you want to contribute there are always some open issues marked as [enhancements](https://github.com/mmick66/CalendarView/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement) in the issues tab. Any help is welcome.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmick66%2Fcalendarview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmick66%2Fcalendarview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmick66%2Fcalendarview/lists"}