func datePickerTapped() {
let locale = Locale(identifier: "zh")
let currentDate = Date()
var dateComponents = DateComponents()
dateComponents.month = -3
let threeMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
dateComponents.month = 12
let nextYearMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
let datePicker = LWDatePickerDialog(textColor: .red,
buttonColor: .red,
font: UIFont.boldSystemFont(ofSize: 17),
locale:locale ,
showCancelButton: true)
datePicker.show("选择日期",
doneButtonTitle: "确定",
cancelButtonTitle: "取消",
minimumDate: threeMonthAgo,
maximumDate: nextYearMonthAgo,
datePickerMode: .date) { (date) in
if let dt = date {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
self.textField.text = formatter.string(from: dt)
}
}
}
更多使用方法可以参照:DatePickerDialog-iOS-Swift做的一些个性化改进。
Swift: 4.0 iOS:10.0及以上
pod 'DatePickerDialogSwift'
zhenxingLiu, 5210167@qq.com
@Squimer的工作,我的项目就是在它的DatePickerDialog-iOS-Swift做的一些个性化改进。
DatePickerDialogSwift is available under the MIT license. See the LICENSE file for more info.