AUCustomDatePicker 为自定义的日期选择控件,目前支持以下几种模式:
AUDatePickerModeTime
:小时/分,24 小时制。AUDatePickerModeDate
:年/月/日。AUDatePickerModeDateAndTime
:月/日/星期/小时/分/,24 小时制。说明年是按照 minimumDate 定义,默认为 2000 年闰年,故存在 2/29。
AUDatePickerYear
:年。AUDatePickerYearMonth
:年/月。
效果图
AUDatePickerModeTime
AUDatePickerModeDate
AUDatePickerModeDateAndTime
AUDatePickerYear
AUDatePickerYearMonth
带自定义 BottomView
接口说明
AUCustomDatePicker.h
//自定义底部 View
@property (nonatomic,strong) UIView *bottomView;
/**
* 创建 Picker,默认使用 AUDatePickerModeDate 模式
*
*/
+ (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title;
+ (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title pickerMode:(AUCustomDatePickerMode)mode;
/**
* 设定可选择的日期区间
@param minDate 最小时间,默认为 2000 年 1 月 1 日 00:00:00,闭
@param maxDate 最大时间,默认为 2050 年 12 月 31 日 23:59:59,闭
*/
- (void) setTimeDateminDate:(NSDate *)minDate MaxDate:(NSDate *)maxDate;
/**
@param currentDate 设置默认选中的时间
*/
- (void) setCurrentDate:(NSDate *) currentDate animated:(BOOL) animated;
/**
展示日期选择控件
*/
-(void) show;
/**
隐藏日期选择控件
*/
-(void) hide;
示例代码
创建
self.apCustomDatePickerView = [AUCustomDatePicker pickerViewWithTitle:@"AUDatePickerYearMonth" pickerMode:AUDatePickerYearMonth]; UIView *customBottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, AUCommonUIGetScreenWidth(), 40)]; customBottomView.backgroundColor = RGB(0x00AAEE); self.apCustomDatePickerView.bottomView = customBottomView; [self.apCustomDatePickerView setCurrentDate:[NSDate date] animated:NO]; self.apCustomDatePickerView.tag = 1004; self.apCustomDatePickerView.delegate = self; [self.view addSubview:self.apCustomDatePickerView];
展示/隐藏
[self.apCustomDatePickerView show]; [self.apCustomDatePickerView hide];
取值
- (void)cancelPickerView:(AUCustomDatePicker *)pickerView { [self.apCustomDatePickerView hide]; } - (void)selectedPickerView:(AUCustomDatePicker *)pickerView { NSDate *selectedDate = picker.selectedDate; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"YYYY-MM-dd HH:mm:ss"; [self.textLabel setText:[formatter stringFromDate:selectedDate]]; [pickerView hide]; }
文档内容是否对您有帮助?