- Xcode 11+
- Swift 5
- iOS 10.0+
pod 'DateRangeSelector', :git => 'https://github.com/boof-tech/DateRangeSelector', :tag => '0.0.3'
import DateRangeSelector
let frame = CGRect(x: 0, y: 50, width: self.view.frame.width, height: 300)
var calendarView: CalendarView = CalendarView(frame: frame)
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
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)
}
}
- 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)
Date Range Selector is available under the MIT license. See the LICENSE.txt file for more info.