项目介绍:
日期选择器,支持年、年月、年月日、时分、年月周 时分等。
由于使用UIPickerView的话,列表会有个弧度,所以这里用了https://github.com/xiaozhuxiong121/PGPickerView
GitHub地址
https://github.com/xiaozhuxiong121/PGDatePicker
CocoaPods安装
pod 'PGDatePicker'
使用
PGDatePicker *datePicker = [[PGDatePicker alloc]init];
datePicker.delegate = self;
[datePicker show];
datePicker.datePickerMode = PGDatePickerModeYear;
#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
NSLog(@"dateComponents = %@", dateComponents);
}
设置Date
建议用NSDate+PGCategory类所定义的方法去设置
+ (NSDate *)setYear:(NSUInteger)year;
+ (NSDate *)setYear:(NSUInteger)year month:(NSUInteger)month;
+ (NSDate *)setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
+ (NSDate *)setMonth:(NSUInteger)month day:(NSUInteger)day hour:(NSInteger)hour minute:(NSInteger)minute;
+ (NSDate *)setHour:(NSInteger)hour minute:(NSInteger)minute;
比如:datePicker.maximumDate = [NSDate setYear:2017];