All Products
Search
Document Center

Mobile Platform as a Service:Custom date picker

Last Updated:Jul 19, 2023

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

    image.png
  • AUDatePickerModeDate

    image.png
  • AUDatePickerModeDateAndTime

    image.png
  • AUDatePickerYear

    image.png
  • AUDatePickerYearMonth

    image.png
  • With a custom bottom view

    image.png

API description

AUCustomDatePicker.h

// The custom bottom view.
@property (nonatomic,strong) UIView *bottomView;


/**
 * Create a picker, in AUDatePickerModeDate mode by default.
 *
 */
+ (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title;

+ (AUCustomDatePicker *)pickerViewWithTitle:(NSString *)title pickerMode:(AUCustomDatePickerMode)mode;


/**
 * Set an available date range.
 @param minDate The earliest time (included), which is 00:00:00 on January 1, 2000 by default.
 @param maxDate The latest time (included), which is 23:59:59 on December 31, 2050 by default.
 */
- (void) setTimeDateminDate:(NSDate *)minDate MaxDate:(NSDate *)maxDate;



/**
 @param currentDate The time selected by default.
 */
- (void) setCurrentDate:(NSDate *) currentDate animated:(BOOL) animated;



/**
 Show the date selection control.
 */
-(void) show;

/**
 Hide the date selection control.
 */
-(void) hide;

Code sample

  • Create

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

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

     - (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];
    
      }