日期范围选择器 0.0.2

日期范围选择器 0.0.2

Amirhosein Memarian维护。




  • Boof.tech

日期范围选择器

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

要求

  • Xcode 11+
  • Swift 5
  • iOS 10.0+

安装

Cocoapods

pod 'DateRangeSelector', :git => '[email protected]:boof-tech/DateRangeSelector.git', :tag => '0.0.2'

使用

导入DateRangeSelector

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)
    }
}

自定义仪表盘

  • 最大日期
calendarView.maxDate = Date() // Limited to show future days
  • 日历标题
calendarView.headerTitleColor = .darkGray
calendarView.headerTitleFont = UIFont.systemFont(ofSize: 18)
calendarView.headerBackgroundColor = UIColor.lightGray.withAlphaComponent(0.5)
  • 上个月和下个月
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
  • 高亮显示
calendarView.highlightColor = UIColor(red: 11/255.0, green: 75/255.0, blue: 105/255.0, alpha: 1)
calendarView.highlightScale = 0.8
  • 今天
calendarView.todayHighlightColor = .red
calendarView.todayTextColor = .white
calendarView.dayTextColor = .gray
calendarView.dayFont = UIFont.systemFont(ofSize: 16)

许可

日期范围选择器可在MIT许可下使用。有关更多信息,请参阅LICENSE.txt文件。