全部产品
云市场
云游戏

自定义日期组件

更新时间:2020-08-07 20:47:01

AUCustomDatePicker 为自定义的日期选择控件,目前支持以下几种模式:

  • AUDatePickerModeTime:小时/分,24小时制
  • AUDatePickerModeDate:年/月/日
  • AUDatePickerModeDateAndTime:月/日/星期/小时/分/,24小时制,

    注意:年是按照 minimumDate 定义,默认为 2000 年闰年,故存在2/29

  • AUDatePickerYear:年
  • AUDatePickerYearMonth:年/月

效果图

  • AUDatePickerModeTime

  • AUDatePickerModeDate

  • AUDatePickerModeDateAndTime

  • AUDatePickerYear

  • AUDatePickerYearMonth

  • 带自定义 BottomView

接口说明

AUCustomDatePicker.h

  1. //自定义底部View
  2. @property (nonatomic,strong) UIView *bottomView;
  3. /**
  4. * 创建 Picker,默认使用 AUDatePickerModeDate 模式
  5. *
  6. */
  7. + (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title;
  8. + (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title pickerMode:(AUCustomDatePickerMode)mode;
  9. /**
  10. * 设定可选择的日期区间
  11. @param minDate 最小时间,默认为 2000 年 1 月 1 日 00:00:00,闭
  12. @param maxDate 最大时间,默认为 2050 年 12 月 31 日 23:59:59,闭
  13. */
  14. - (void) setTimeDateminDate:(NSDate *)minDate MaxDate:(NSDate *)maxDate;
  15. /**
  16. @param currentDate 设置默认选中的时间
  17. */
  18. - (void) setCurrentDate:(NSDate *) currentDate animated:(BOOL) animated;
  19. /**
  20. 展示日期选择控件
  21. */
  22. -(void) show;
  23. /**
  24. 隐藏日期选择控件
  25. */
  26. -(void) hide;

示例代码

  • 创建:

    1. self.apCustomDatePickerView = [AUCustomDatePicker pickerViewWithTitle:@"AUDatePickerYearMonth" pickerMode:AUDatePickerYearMonth];
    2. UIView *customBottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, AUCommonUIGetScreenWidth(), 40)];
    3. customBottomView.backgroundColor = RGB(0x00AAEE);
    4. self.apCustomDatePickerView.bottomView = customBottomView;
    5. [self.apCustomDatePickerView setCurrentDate:[NSDate date] animated:NO];
    6. self.apCustomDatePickerView.tag = 1004;
    7. self.apCustomDatePickerView.delegate = self;
    8. [self.view addSubview:self.apCustomDatePickerView];
  • 展示/隐藏

    1. [self.apCustomDatePickerView show];
    2. [self.apCustomDatePickerView hide];
  • 取值

    1. - (void)cancelPickerView:(AUCustomDatePicker *)pickerView
    2. {
    3. [self.apCustomDatePickerView hide];
    4. }
    5. - (void)selectedPickerView:(AUCustomDatePicker *)pickerView
    6. {
    7. NSDate *selectedDate = picker.selectedDate;
    8. NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    9. formatter.dateFormat = @"YYYY-MM-dd HH:mm:ss";
    10. [self.textLabel setText:[formatter stringFromDate:selectedDate]];
    11. [pickerView hide];
    12. }