此端口是为了使 DatePickerDialog 的功能可以在 Objective-C 项目中使用,而无需在您的应用程序二进制文件中导入 Swift 运行时(这可能会非常大增加应用程序二进制文件的大小)
DatePickerDialog 是一个 iOS 抽象类,它可以在 UIAlertView 中显示 UIDatePicker。
DatePickerDialog 在 iOS 8、9 和 10 上运行。它依赖于以下 Apple 框架,这些框架应该已经包含在大多数 Xcode 模板中:
LSLDatePickerDialog.h
和 LSLDatePickerDialog.m
。#import "LSLDatePickerDialog.h"
@implementation ViewController {
-(void)openDatePicker {
LSLDatePickerDialog *dpDialog = [[LSLDatePickerDialog alloc] init];
[dpDialog showWithTitle:@"DatePicker" doneButtonTitle:@"Done" cancelButtonTitle:@"Cancel"
defaultDate:[NSDate date] minimumDate:nil maximumDate:nil datePickerMode:UIDatePickerModeDate
callback:^(NSDate * _Nullable date){
if(date)
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSLog(@"Date selected: %@",[formatter stringFromDate:date]);
}
}
];
}
不带 '取消' 按钮的示例初始化
LSLDatePickerDialog *dpDialog = [[LSLDatePickerDialog alloc] initWithCancelButton:NO];
带 locale 的示例初始化
LSLDatePickerDialog *dpDialog = [[LSLDatePickerDialog alloc] initWithLocale:[Locale localeWithLocaleIdentifier:@“ja_JP”]];
本代码根据MIT许可协议分发。