All Products
Search
Document Center

Custom date picker

Last Updated: May 25, 2021

ACustomDatePicker is a custom date selection control and currently supports the following modes:

  • AUDatePickerModeTime: hour/minute, 24-hour clock
  • AUDatePickerModeDate: year/month/day
  • AUDatePickerModeDateAndTime: month/day/day of week/hour/minute, 24-hour clock

    Note: The year is defined based on minimumDate and is 2000 (leap year) by default. Therefore, February 29 exists.
  • AUDatePickerYear: year

  • AUDatePickerYearMonth: year/month

Sample images

  • AUDatePickerModeTime

  • AUDatePickerModeDate

  • AUDatePickerModeDateAndTime

  • AUDatePickerYear

  • AUDatePickerYearMonth

  • With a custom bottom view

API description

AUCustomDatePicker.h

 
  1. // The custom bottom view.
  2. @property (nonatomic,strong) UIView *bottomView;
  3. /**
  4. * Create a picker, in AUDatePickerModeDate mode by default.
  5. *
  6. */
  7. + (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title;
  8. + (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title pickerMode:(AUCustomDatePickerMode)mode;
  9. /**
  10. * Set an available date range.
  11. @param minDate The earliest time (included), which is 00:00:00 on January 1, 2000 by default.
  12. @param maxDate The latest time (included), which is 23:59:59 on December 31, 2050 by default.
  13. */
  14. - (void) setTimeDateminDate:(NSDate *)minDate MaxDate:(NSDate *)maxDate;
  15. /**
  16. @param currentDate The time selected by default.
  17. */
  18. - (void) setCurrentDate:(NSDate *) currentDate animated:(BOOL) animated;
  19. /**
  20. Show the date selection control.
  21. */
  22. -(void) show;
  23. /**
  24. Hide the date selection control.
  25. */
  26. -(void) hide;

Code sample

  • Create

       
    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];
  • Show/Hide

       
    1. [self.apCustomDatePickerView show];
    2. [self.apCustomDatePickerView hide];
  • Value

       
    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. }