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

Customizable calendar view as a date range selector

License

Notifications You must be signed in to change notification settings

tiss-co/DateRangeSelector

Repository files navigation

DateRangeSelector

Screen Shot 2021-03-10 at 4 02 20 PM

Requirements

  • Xcode 11+
  • Swift 5
  • iOS 10.0+

Installation

Cocoapods

pod 'DateRangeSelector', :git => 'https://github.com/boof-tech/DateRangeSelector', :tag => '0.0.3'

Usage

Import DateRangeSelector

import DateRangeSelector

Create an instance of Calendar

let frame = CGRect(x: 0, y: 50, width: self.view.frame.width, height: 300)
var calendarView: CalendarView = CalendarView(frame: frame)

Setup Calendar

calendarView.monthRange = 12 // Show the 12 month ago of Max Date
calendarView.selectedYear = 2019 // The defult value is now year but when you set selected year, the range month of year is changed

Delegate

class ViewController: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()
    ...
    calendarView.delegate = self
}
...
}

extension ViewController: CalendarViewDelegate {
    func didSelectDate(startDate: Date, endDate: Date) {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "MMM d, yyyy"
        fromValueLabel.text = dateFormatter.string(from: startDate)
        toValueLabel.text = dateFormatter.string(from: endDate)
    }
}

Customize gauge

  • Max Date
calendarView.maxDate = Date() // Limited to show future days
  • Header Calendar
calendarView.headerTitleColor = .darkGray
calendarView.headerTitleFont = UIFont.systemFont(ofSize: 18)
calendarView.headerBackgroundColor = UIColor.lightGray.withAlphaComponent(0.5)
  • Previous and Next Month
calendarView.previousButtonIsEnable = true
calendarView.nextButtonIsEnable  = true
calendarView.previousButtonTitleColor = .darkGray
calendarView.previousButtonTitleFont = UIFont.systemFont(ofSize: 20)
calendarView.previousButtonAligment = .right
calendarView.nextButtonTitleColor = .darkGray
calendarView.nextButtonTitleFont = UIFont.systemFont(ofSize: 20)
calendarView.nextButtonAligment = .left
  • Highlight
calendarView.highlightColor = UIColor(red: 11/255.0, green: 75/255.0, blue: 105/255.0, alpha: 1)
calendarView.highlightScale = 0.8
  • Today
calendarView.todayHighlightColor = .red
calendarView.todayTextColor = .white
  • Day
calendarView.dayTextColor = .gray
calendarView.dayFont = UIFont.systemFont(ofSize: 16)

Licence

Date Range Selector is available under the MIT license. See the LICENSE.txt file for more info.

About

Customizable calendar view as a date range selector

Resources

License

Stars

Watchers

Forks

Packages

No packages published