Simple customizable calendar component in Swift :calendar:

Overview

Koyomi

Koyomi is a simple calendar view framework for iOS, written in Swift πŸ“†

Content

:octocat: Features

Platform Carthage compatible License Awesome Swift pod GitHub stars

  • Simple Calendar View πŸ“†
  • Easily usable 😎
  • Customizable in any properties for appearance
  • Selectable calender
  • Complete README
  • Support @IBDesignable and @IBInspectable
  • Compatible with Carthage
  • Support Swift 2.3.
  • Support Swift 3.0

Demo App

Open Example/Koyomi.xcworkspace and run Koyomi-Example to see a simple demonstration.

Usage

Koyomi is designed to be easy to use 😎

    let frame = CGRect(x: 10, y : 20, width: 250, height: 300)
    let koyomi = Koyomi(frame: frame, sectionSpace: 1.5, cellSpace: 0.5, inset: .zero, weekCellHeight: 25)
    view.addSubview(koyomi)

Koyomi is available in Interface Builder. Set custom class of UICollectionView to Koyomi

    @IBOutlet weak var koyomi: Koyomi!

πŸ“† Change displayed month

If you want to change displayed month, call display(in: MonthType). MonthType is defined by three types.

    public enum MonthType { case previous, current, next }
    
    // change month
    koyomi.display(in: .next)

Hide days of other months

If you want to hide days of other months, set isHiddenOtherMonth to true. Days of other months aren't displayed and user can't select.

    koyomi.isHiddenOtherMonth = true

Get current month string

    let currentDateString = koyomi.currentDateString()

NOTE

If you want to change dateFormat of currentDateString, set argument to format. currentDateString(withFormat: "MM/yyyy")

default dateFormat of currentDateString is M/yyyy

The selection state of date

You can configure SelectionMode with style.

SelectionMode has nested enumerations type: SequenceStyle, Style.

    public enum SelectionMode {
        case single(style: Style), multiple(style: Style), sequence(style: SequenceStyle), none
    
        
        public enum SequenceStyle { case background, circle, semicircleEdge, line }
        public enum Style { case background, circle, line }
   }
    
    // default selectionMode is single, circle style
    public var selectionMode: SelectionMode = .single(style: .circle)
    
    // call selectionStyle
    koyomi.selectionMode = .single(style: .circle)
single
SelectionMode .single(style: .background) .single(style: .circle) .single(style: .line)
multiple
SelectionMode .multiple(style: .background) .multiple(style: .circle) .multiple(style: .line)
sequence γ€€
SelectionMode .sequence(style: .background) .sequence(style: .circle) .sequence(style: .semicircleEdge) .sequence(style: .line)

You can configure lineView in the case of line style.

public struct LineView {
    public enum Position { case top, center, bottom }
    public var height: CGFloat = 1
    public var widthRate: CGFloat = 1 // default is 1.0 (0.0 ~ 1.0)
    public var position: Position = .center
}

koyomi.selectionMode = .single(style: .line)
koyomi.lineView.height = 3
koyomi.lineView.position = .bottom
koyomi.lineView.widthRate = 0.7

NOTE

If you don't want to allow user to select date by user interaction, set selectionMode to .none.

Select date in programmatically

You can select specific date .

    let today = Date()
    var components = DateComponents()
    components.day = 7
    let weekLaterDay = Calendar.current.date(byAdding: components, toDate: today)
    koyomi.select(date: today, to: weekLaterDay)
    
    // If want to select only one day. 
    koyomi.select(date: today)
    
    // If want to select multiple day.
    let dates: [Date] = [date1, date2, date3]
    koyomi.select(dates: dates)

You can also unselect available.

    koyomi.unselect(today, to: weekLaterDay) 
    // If want to unselect only one day.
    koyomi.unselect(today)
    // If want to unselect multiple day.
    let dates: [Date] = [date1, date2, date3]
    koyomi.unselect(dates: dates)
    
    // unselect all date
    koyomi.unselectAll()

You can configure style color and text state in selected state.

    @IBInspectable public var selectedStyleColor: UIColor
    
    public enum SelectedTextState { case change(UIColor), keeping }
    public var selectedDayTextState: SelectedTextState

selectedDayTextState

If you want to change day textColor when the user selects day in the Koyomi, set selectedDayTextState to SelectedTextState.change(UIColor).

Also, if you don't want to change day textColor when the user selects day, set selectedDayTextState to SelectedTextState.keeping.

// day text color change white when selected.
koyomi.selectedDayTextState = .change(.white)

// day text color doesn't change when selected.
koyomi.selectedDayTextState = .keeping

Highlight specific days

You can change dayColor and dayBackgroundColor in specific days.

    koyomi
        .setDayColor(.white, of: today, to: weekLaterDay)
        .setDayBackgrondColor(.black, of: today, to: weekLaterDay)
        
        // set day color only one day.
        // .setDayColor(.white, of: today)
        // .setDayBackgrondColor(.black, of: today)

KoyomiDelegate

If you want to use KoyomiDelegate, set calendarDelegate to target

    koyomi.calendarDelegate = self

Declaration

koyomi(_: didSelect: forItemAt)

    optional func koyomi(_ koyomi: Koyomi, didSelect date: Date, forItemAt indexPath: IndexPath) 

Tells the delegate that the date at the specified index path was selected. date: the date user selected, when tapped cell

koyomi(_: currentDateString:)

   optional func koyomi(_ koyomi: Koyomi, currentDateString dateString: String)
    
    // if you want to change string format, use `currentDateFormat`
    koyomi.currentDateFormat = "M/yyyy"

Tells the delegate that the displayed month is changed. currentDateString: the current month string, when changed month.

koyomi(_: shouldSelectDates: to: withPeriodLength)

    optional func koyomi(_ koyomi: Koyomi, shouldSelectDates date: Date?, to toDate: Date?, withPeriodLength length: Int) -> Bool
    
    //γ€€control date user selected.
    func koyomi(_ koyomi: Koyomi, shouldSelectDates date: Date?, to toDate: Date?, withPeriodLength length: Int) -> Bool {
    
        if invalidStartDate <= date && invalidEndDate >= toDate {
            print("Your select day is invalid.")
            return false
        }
    
        if length > 90 {
            print("More than 90 days are invalid period.")
            return false
        }
        
        return true
    }

koyomi calls this method before select days. return value: true if the item should be selected or false if it should not. to is always nil if selectionMode isn't sequence.

koyomi(_: selectionColorForItemAt: date:)

    optional func koyomi(_ koyomi: Koyomi, selectionColorForItemAt indexPath: IndexPath, date: Date) -> UIColor?
    
    func koyomi(_ koyomi: Koyomi, selectionColorForItemAt indexPath: IndexPath, date: Date) -> UIColor? {
        return today == date ? UIColor.black : nil
    }

koyomi calls this method before setting selectionColor for specific date. return value: UIColor instance for a different color then the default one or return nil to use the default color.

koyomi(_: fontForItemAt: date:)

    func koyomi(_ koyomi: Koyomi, fontForItemAt indexPath: IndexPath, date: Date) -> UIFont?
    
    func koyomi(_ koyomi: Koyomi, fontForItemAt indexPath: IndexPath, date: Date) -> UIFont? {
        return today == date ? UIFont(name:"FuturaStd-Bold", size:16) : nil
    }

koyomi calls this method before setting font for specific date. return value: UIFont instance for a different font then the default one or return nil to use the default font.

πŸ”§ Customize Koyomi

Customize layout properties

    // Support @IBInspectable properties
    @IBInspectable var sectionSpace: CGFloa
    @IBInspectable var cellSpace: CGFloat
    @IBInspectable var weekCellHeight: CGFloat
    // Public property
    public var inset: UIEdgeInsets

    koyomi.inset = UIEdgeInsets(top: 0.5, left: 0.5, bottom: 0.5, right: 0.5)

Set sectionSpace, cellSpace, weekCellHeight in initialization or Interface Builder.

Customize text postion

    public enum ContentPosition {
        case topLeft, topCenter, topRight
        case left, center, right
        case bottomLeft, bottomCenter, bottomRight
        case custom(x: CGFloat, y: CGFloat)
    }

You can configure text postion.

    // default is .center
    koyomi.dayPosition = .topRight
    koyomi.weekPosition = .center
    
    // custom case
    koyomi.dayPosition = .custom(x: 1.2, y: 2.3)

Customize text font

    // set Day and Week Label Font
    koyomi
        .setDayFont(size: 12) 
        .setWeekFont(size: 8)
        
    // if want to change font name, 
    setDayFont(fontName: ".SFUIText-Medium", size: 12)

Customize weeks text

   koyomi.weeks = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
   
   // configure with index
   koyomi.weeks.0 = "Sun"
   koyomi.weeks.1 = "Mon"
   koyomi.weeks.2 = "Tue"
   ...

Customize color properties

    // Support @IBInspectable properties
    @IBInspectable public var sectionSeparatorColor: UIColor
    @IBInspectable public var separatorColor: UIColor
    @IBInspectable public var weekColor: UIColor
    @IBInspectable public var weekdayColor: UIColor
    @IBInspectable public var holidayColor: UIColor
    @IBInspectable public var otherMonthColor: UIColor
    @IBInspectable public var dayBackgrondColor: UIColor
    @IBInspectable public var weekBackgrondColor: UIColor
    @IBInspectable public var selectedStyleColor: UIColor

You can configure the lots of color properties for appearance 😩

Don't worry 😝 , you can easily configure appearance by using KoyomiStyle.

    koyomi.style = .tealBlue

KoyomiStyle is defined by 19 types + 1 custom. used iOS Human Interface Guidelines as reference

    enum KoyomiStyle {
        // basic color style
        case monotone, standard, red, orange, yellow, tealBlue, blue, purple, green, pink
        // deep color style
        case deepBlack, deepRed, deepOrange, deepYellow, deepTealBlue, deepBlue, deepPurple, deepGreen, deepPink
        
        case custom(customColor: CustomColorScheme)
    }

To use a custom color scheme, you need to define tuple with the necessarry values

    // This is a replica of the `.deepRed` style, you can unleash your creativity here:
    let customColorScheme = (dayBackgrond: UIColor.KoyomiColor.red,
                           weekBackgrond: UIColor.KoyomiColor.red,
                           week: .white,
                           weekday: .white,
                           holiday: (saturday: UIColor.white, sunday: UIColor.white),
                           otherMonth: UIColor.KoyomiColor.lightGray,
                           separator: UIColor.KoyomiColor.orange)
            
    koyomi.style = KoyomiStyle.custom(customColor: customColorScheme)

πŸ“ Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

πŸ’» Installation

Installation of Swift 2.3

Please install version 0.1.6 or earlier.

pod 'Koyomi', '~> 0.1.6'

CocoaPods

Koyomi is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Koyomi"

Carthage

Add the following line to your Cartfile:

github "shoheiyokoyama/Koyomi"

App using Koyomi

If you're using Koyomi in your app, please open a PR to add it to this list! 😊

Contributing

See the CONTRIBUTING file

β˜• Author

shoheiyokoyama, [email protected]

πŸ”“ License

Koyomi is available under the MIT license. See the LICENSE file for more info.

Comments
  • Next Month days

    Next Month days

    Currently calendar displays up to two weeks of the next month, and one for the past. How to make max one for the next month?

    I don't want 6-12 week of the next month to be displayed. What should I do?

    screen shot 2017-02-19 at 00 52 59
    opened by piv199 4
  • Some useful features

    Some useful features

    • added ability to define selection colours for individual cells via delegate
    • added ability to define font for individual cells via delegate (can be used for example to display current day in bold)
    • added ability to define the circle size for selection (from hardcoded 75%)
    opened by EvilClay 4
  • IB Designables Errors

    IB Designables Errors

    When I add the class to my collection view I get Failed to render and update auto layout status for my viewController. Also get Failed to update auto layout status: The agent crashed

    opened by christstuart 4
  • Enable only some days to be selected + highlight those

    Enable only some days to be selected + highlight those

    Is it possible to only enable some days to be selected and highlight those that can?

    I need to let user know on which days there is an event going on and don't want them to select days other than those with events. Is something like this possible with Koyomi?

    Thanks!

    opened by TadeasKriz 3
  • Added missing 'public' access level

    Added missing 'public' access level

    Although these properties were marked @IBInspectable they lacked the public keyword, meaning they defaulted to internal.

    koyomi.cellSpace = 1 // 'cellSpace' is inaccessible due to 'internal' protection level
    koyomi.sectionSpace = 1 // 'sectionSpace' is inaccessible due to 'internal' protection level
    koyomi.weekCellHeight = 25 // 'weekCellHeight' is inaccessible due to 'internal' protection level
    

    As a result these properties could be set with interface builder. But only with interface builder.

    opened by kylehowells 1
  • Last version on Cocoapods

    Last version on Cocoapods

    Just letting you know that the last version available on Cocoapods is still 0.1.0 (https://cocoapods.org/?q=koyomi). Would be great to push the last podspec if it's not an issue for you.

    Thanks!

    opened by Nonouf 1
  • Unable to reference in code.

    Unable to reference in code.

    I added the line pod "Koyomi" to my podfile and did the pod install and that seemed to work fine, then I went to my Main.storyboard and I dragged a collection view. I then chose its class to be Koyomi in the identity inspector, and everything seemed to still be fine. I see the options to modify it in the attributes inspector, but then when I try to control-drag it to my .swift file, it gives me the following errors: screenshot any help with this would be much appreciated.

    opened by thom5409 0
  • NSLayoutConstraint warning

    NSLayoutConstraint warning

    Hi, there I got warning occurring every time Koyomi is added to superview

    "This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit(void) to debug. This will be logged only once. This may break in the future."

    opened by LesykMelnychuk 0
  • localizable Issue

    localizable Issue

    Hello I have issue on localizable when change device language calendar language change I can't control of calendar language or fixing calendar language ?!

    opened by amjadmansor 0
  • Disable some days

    Disable some days

    Heya, I was wondering if there is a way to set some days of the calendar disabled, and that they also look disabled, like grayed out.

    I don't mean using shouldSelectDates

    I mean showing for example the 12th and 13th and 20th to lok lie the 25th of the previous month. imagen

    I try searching but I didn't found anything.

    Thanks!

    opened by SonicGerkor 2
Owner
Shohei Yokoyama
iOS Engineer at @smartnews ex-@CyberAgent
Shohei Yokoyama
A declarative, performant, iOS calendar UI component that supports use cases ranging from simple date pickers all the way up to fully-featured calendar apps.

HorizonCalendar A declarative, performant, calendar UI component that supports use cases ranging from simple date pickers all the way up to fully-feat

Airbnb 2.2k Jan 4, 2023
RCalendarPicker A date picker control, Calendar calendar control, select control, calendar, date selection, the clock selection control.

RCalendarPicker RCalendarPicker Calendar calendar control, select control, calendar, date selection, the clock selection control. ζ—₯εŽ†ζŽ§δ»Ά ,ζ—₯εŽ†ι€‰ζ‹©ζŽ§δ»ΆοΌŒζ—₯εŽ†οΌŒζ—₯ζœŸι€‰ζ‹©

ζœθ€€θΎ‰ 131 Jul 18, 2022
Calendar component with RTL languages written in swift

GDCalendar Calendar component with both RTL/LTR languages support with Swipe Gesture enabled navigation. Easy to use with Storyboard and Attributes In

Saeid 26 Jul 17, 2022
A Swift UI component for Lunar Calendar Picker

LunarYearDatePicker a Swift UI component for Lunar Calendar Picker Usage: struct

null 6 Nov 22, 2022
Malendar is a personal calendar app that connects to your default calendar and lets you add/delete events

Malendar is a personal calendar app that connects to your default calendar and lets you add/delete events. It will gather events from your default iOS calendar.

Chase 194 Jan 4, 2023
A fully customizable iOS calendar library, compatible with Objective-C and Swift

Table of contents Screenshots Installation Pre-knowledge Support Contact Screenshots iPhone iPad Safe Orientation Today Extension iOS8/9 iOS10 Interac

Wenchao Ding 10.2k Jan 2, 2023
A customizable swiftui calendar

Description not available. Installation From Xcode 11, you can use Swift Package Manager to add Kingfisher to your project. Select File > Swift Packag

Heshan Yodagama 140 Dec 24, 2022
A fully customizable calendar view acting as a date range picker

Demo Installation CocoaPods With CocoaPods you can simply add GLCalendarView in your Podfile: pod "GLCalendarView", "~> 1.0.0" Source File You can co

Glow Inc 860 Nov 18, 2022
A customizable calendar view for iOS.

JTCalendar JTCalendar is an easily customizable calendar control for iOS. Installation With CocoaPods, add this line to your Podfile. pod 'JTCalendar'

Jonathan Vukovich-Tribouharet 2.8k Dec 27, 2022
SwiftUI Simple Calendar / Date Picker for iOS

RKCalendar RKCalendar is a SwiftUI Calendar / Date Picker for iOS. Features include: minimum and maximum calendar dates selectable, single date select

null 453 Dec 28, 2022
SwiftUICalendar - SwiftUI simple calendar

SwiftUICalendar Installation CocoaPods pod 'SwiftUICalendar' import import SwiftUICalendar Features Infinite scroll Support horizontal and vertical sc

null 59 Dec 27, 2022
Dead simple calendar implementation

Package provides a CalendarView which can be used to display simple calendar in your App.

Sergei Kononov 4 Oct 7, 2022
Calendar View - It's lightweight and simple control with supporting Locale and CalendarIdentifier.

iOS Calendar It's lightweight and simple control with supporting Locale and CalendarIdentifier. There're samples for iPhone and iPad, and also with us

Maksym Bilan 159 Dec 22, 2022
CalendarApp Swift - Made a calendar app in swift, completely from scratch using UIStackView and UICollectionView

CalendarApp_Swift Made a calendar app in swift, completely from scratch using UI

Arnav Chhokra 1 Feb 4, 2022
A nicer iOS UI component for picking date and time

DateTimePicker A nicer iOS UI component for picking date and time. Features Date and Time Picker / Date Picker only / Time Picker only - your choice!

Huong Do 1.9k Jan 4, 2023
πŸ“… Calendar for iOS, iPadOS and macOS in Swift

CalendarKit CalendarKit is a Swift calendar UI library for iOS, iPadOS and Mac Catalyst. It looks similar to the Apple Calendar app out-of-the-box, wh

Richard Topchii 2.2k Jan 5, 2023
An Easy to Use Calendar for iOS (Swift 5.0)

This 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

Michael Michailidis 525 Dec 23, 2022
A custom visual calendar for iOS 8+ written in Swift (>= 4.0).

Overview Screenshots GIF Demo Installation Usage Architecture Version matrix Advanced API For contributors Screenshots GIF Demo Installation CocoaPods

null 3.5k Dec 24, 2022
A calendar control for iOS written in swift with mvvm pattern

ASCalendar try it on appetize Installation CocoaPods You can use CocoaPods to install ASCalendar by adding it to your Podfile: platform :ios, '8.0' us

Alberto Scampini 192 Jun 26, 2022