快速自定义视图中的多个日期范围选择

Sat*_*mar 2 calendar objective-c custom-view ios swift

我需要像这样的图片开发日历。我搜索了很多库。但是没有一个人类似于这个自定义选择视图。请有人帮我。谢谢。

在此处输入图片说明

Rav*_*iya 5

我认为您正在使用此库:Koyomi

以编程方式选择日期

您可以选择特定日期。

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)
Run Code Online (Sandbox Code Playgroud)

您也可以取消选择可用。

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 also call this delegate.    

extension ViewController: KoyomiDelegate {
    func koyomi(_ koyomi: Koyomi, didSelect date: Date?, forItemAt indexPath: IndexPath) {
        print("You Selected: \(date)")
    }

    func koyomi(_ koyomi: Koyomi, currentDateString dateString: String) {
        currentDateLabel.text = dateString
    }

    @objc(koyomi:shouldSelectDates:to:withPeriodLength:)
    func koyomi(_ koyomi: Koyomi, shouldSelectDates date: Date?, to toDate: Date?, withPeriodLength length: Int) -> Bool {
        if length > invalidPeriodLength {
            print("More than \(invalidPeriodLength) days are invalid period.")
            return false
        }
        return true
    }
}
Run Code Online (Sandbox Code Playgroud)

这对我有用。您可以尝试该库。