NDCollapsiveDatePicker 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'NDCollapsiveDatePicker'
要运行示例项目,先从仓库克隆,然后在 NDCollapsiveDateViewDemo 目录下运行 pod install
在 .h 文件中添加到协议的代理
#import <NDCollapsiveDatePicker/NDCollapsiveDateView.h>
@interface NDViewController : UIViewController <NDCollapsiveDateViewDelegate>
使用两种初始化方法之一
NDCollapsiveDateView collapsiveDateView = [[NDCollapsiveDateView alloc] initWithFrame:frame title:@"Date" andImage:[UIImage imageNamed:@"calendar"]];
[collapsiveDateView setShown:200.f andHiddenHeight:50];
或者使用组合初始化方法
NDCollapsiveDateView collapsiveDateView = [[NDCollapsiveDateView alloc] initWithFrame:frame title:@"Date" andImage:UIImage imageNamed:@"calendar" hiddenHeight:50 andShownHeight:200.f];
设置代理
collapsiveDateView.delegate = self;
包含代理方法
-(void)datePickerViewDidCollapse:(NDCollapsiveDatePickerView *)datePickerView
从 NDCollapsiveDateView 获取所选日期的示例
-(void)datePickerViewDidCollapse:(NDCollapsiveDatePickerView *)datePickerView {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *stringDate = [dateFormatter stringFromDate:datePickerView.date];
NSLog(@"selected date: %@",stringDate);
}
请随意自定义 NDCollapsiveDateView
collapsiveDateView.backgroundColor = [UIColor whiteColor];
collapsiveDateView.layer.borderColor = [[UIColor blackColor] CGColor];
...
动画 gif,显示正在工作的 NDCollapsiveDateView
Simon Wicha | [email protected]
NDCollapsiveDatePicker 基于 MIT 许可证可用。有关更多信息,请参阅 LICENSE 文件。