ios - 在 swift 3 中使用自定义 View 选择多个日期范围

标签 ios objective-c swift calendar custom-view

我需要像这张附加图片一样开发日历。我搜索了很多图书馆。但没有人与这个自定义选择 View 相似。请有人帮助我。谢谢..

enter image description here

最佳答案

我想你使用这个库: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)

您也可以取消选择可用的。

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

这对我有用。你可以试试那个库。

关于ios - 在 swift 3 中使用自定义 View 选择多个日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45340801/

相关文章:

ios - 处理 UI 中的异步事件

ios - 在飞行模式下从 coreData 加载数据时崩溃

ios - CGContext:如何删除位图上下文之外的像素(例如 kCGBlendModeClear)?

ios - 回调 swift 3 中的标签未更改

ios - 当我使用 ReactiveKit/Bond 调用 becomeFirstResponder 后,UITextField 立即退出第一响应者

ios - 如何使用 swift 为多注释设置数组

ios - 如何访问存储在 UICollectionViewController 中的 Collection View Cell 中的变量

ios - 我可以通过编程方式让 UITabBarController 切换选项卡吗?

ios - 使用照片框架从照片库中删除照片

iphone - 使用自己的按钮(不是预定义的按钮)创建自己的 UI。它们是什么类型的物体?