DatePickerKit
DatePickerKit 是一个用于日期选择的管理工具,支持日期控件的系统风格和自定义风格,可设置最大最小时间、设置各种参数来实现不同风格的UI
Requirements
- iOS 8.0+
- Xcode 9.0+
- Foundation
- UIKit
Swift Versions
- Swift 3.0+
Installation
You can use CocoaPods to install DatePickerKit
by adding it to your Podfile
:
pod 'DatePickerKit'
To get the full benefits import DatePickerKit
wherever you import UIKit
import UIKit
import DatePickerKit
Manually
- Download and drop
DatePickerKit.swift
in your project. - Congratulations!
Example
1.系统UI风格
func datePickerTapped(actionPosition: ActionPosition, titile: String? = "") {
let currentDate = Date()
var dateComponents = DateComponents()
dateComponents.month = -3
let threeMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
let datePicker = SystemDatePicker(title: titile,
textColor: .black,
buttonColor: .red,
font: .boldSystemFont(ofSize: 17),
showCancelButton: true,
actionPosition: actionPosition,
viewSize: nil,
locale: Locale(identifier: "zh_CN"))
datePicker.show(minimumDate: threeMonthAgo, maximumDate: currentDate, datePickerMode: .date) { [weak self] (date) in
if let dt = date {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
if actionPosition == .center {
self?.vertifyBtn.setTitle(formatter.string(from: dt), for: .normal)
}else{
self?.openBtn.setTitle(formatter.string(from: dt), for: .normal)
}
}
}
}
2.自定义UI风格
func customizeShow() {
let picker = CustomizeDatePicker(datePickerStyle: .yearMonthDay, scrollToDate: Date()) { [weak self](date) in
if let dt = date {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
self?.closeBtn.setTitle(formatter.string(from: dt), for: .normal)
}
}
// 可自定义picker参数
//picker.datePickerColor = .green
//picker.maxLimitDate = Date()
picker.show()
}
parameters
具体可修改参数请移步代码查看
图片演示
License
This code is distributed under the terms and conditions of the MIT license.