Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
/ CalendarMenu Public archive

Customizable calendar (Date range picker) menu for iOS (CocoaPods)

License

Notifications You must be signed in to change notification settings

ugalek/CalendarMenu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CalendarMenu

Platform iOS Swift 5 compatible License: MIT

Customizable calendar menu for iOS (13.0 or later), written in Swift 5.

Used at my app Kaniotte

  • UIControl subclass for date / week / month selection
  • I18n / i10n aware
  • Themable

Example

Run the example project:

$ git clone [email protected]:ugalek/CalendarMenu.git
$ cd CalendarMenu
$ pod install

Usage

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

pod 'CalendarMenu'

Integration

Import CalendarMenu:

import CalendarMenu

Define a CalendarMenu view IBOutlet (here, named cMenu):

@IBOutlet weak var cMenu: CalendarMenu!

Add a DateField object that will handle the target:

dateField.delegate = self
dateField.addTarget(self, action: #selector(textFieldTapped), for: .touchDown)

Then the related @objc method that will call the showCalendarMenu() method:

@objc func textFieldTapped() {
    cMenu.showCalendarMenu()
}

The selected date can be handled by .valueChanged action:

cMenu.addTarget(self, action: #selector(cMenuValueChanged), for: .valueChanged)

@objc func cMenuValueChanged() {
    calendarInterval = cMenu.calendarInterval
    dateField.text = cMenu.dateIntervalLabel.text
    switch calendarInterval {
    case .Day:
        dateOfCalendar = cMenu.dayOfCalendar ?? Date()
    case .Week:
        firstDayOfCalendar = cMenu.firstDayOfCalendar
        lastDayOfCalendar = cMenu.lastDayOfCalendar
    case .Month:
        monthOfCalendar = cMenu.monthOfCalendar ?? Date().startOfMonth
    }
}

Theming

Customizing fonts and colors is as simple as setting a few properties.

Let's take an example by changing date interval font and button tint color:

cMenu.style.fontDateInterval = UIFont.systemFont(ofSize: 17.0, weight: .light)
cMenu.style.buttonTintColor = .red
Property Description
bgColor View background color
fontDateInterval Date interval label font
segmentControlTintColor Segment control tint color
selectedSegmentTintColor Segment control selected item color
buttonTintColor Button tint color
buttonBorderColor Button border color

Localization

If your project is localized, you can edit Localizable.strings to customize strings:

"Day" = "Jour";
"Week" = "Semaine";
"Month" = "Mois";
"Today" = "Aujourd'hui";

Buy Me A Coffee

License

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