UIDatePicker, setting maximum and minimum dates based on todays date

Not tested, but you probably want something like this. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *currentDate = [NSDate date]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setYear:30]; NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0]; [comps setYear:-30]; NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0]; [datePicker setMaximumDate:maxDate]; [datePicker setMinimumDate:minDate]; Update for Swift 4.1 let calendar = … Read more

UIDatePicker show only month and day

You cannot use the UIDatePicker class as it stands to do this – The UIDatePicker only supports the following modes typedef enum { UIDatePickerModeTime, UIDatePickerModeDate, UIDatePickerModeDateAndTime, UIDatePickerModeCountDownTimer } UIDatePickerMode; Create a view and controller that implement the UIPickerViewDelegate and create your own – you may find a little more detail here Fixed labels in the … Read more

problem when cloning jQuery UI datepicker

This works for me with jQuery UI 1.7.2 var mydiv = $(‘#someDiv’); mydiv.find(‘input.datefield’).datepicker(); var newDiv = mydiv.clone(false).attr(“id”, “someDiv2”).insertAfter(mydiv); newDiv.find(‘input.datefield’) .attr(“id”, “”) .removeClass(‘hasDatepicker’) .removeData(‘datepicker’) .unbind() .datepicker(); Check http://jsbin.com/ahoqa3/2 for a quick demo btw. you seem to have different errors in the code of your question. The css class is hasDatepicker not hadDatepicker and at one time … Read more

UIDatePicker in UIPopover

Try with below code. It will work fine: Objective-C – (IBAction)showDatePicker:(UIButton *)sender { UIDatePicker *datePicker = [[UIDatePicker alloc]init];//Date picker datePicker.frame = CGRectMake(0, 0, 320, 216); datePicker.datePickerMode = UIDatePickerModeDateAndTime; [datePicker setMinuteInterval:5]; [datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];//need to implement this method in same class UIView *popoverView = [[UIView alloc] init]; //view popoverView.backgroundColor = [UIColor clearColor]; [popoverView addSubview:datePicker]; // … Read more

Fitting a UIDatePicker into a UIActionSheet

You can use something like this (adjust the coordinates): UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@”Date Picker” delegate:self cancelButtonTitle:@”Cancel” destructiveButtonTitle:nil otherButtonTitles:nil]; // Add the picker UIDatePicker *pickerView = [[UIDatePicker alloc] init]; pickerView.datePickerMode = UIDatePickerModeDate; [menu addSubview:pickerView]; [menu showInView:self.view]; [menu setBounds:CGRectMake(0,0,320, 500)]; CGRect pickerRect = pickerView.bounds; pickerRect.origin.y = -100; pickerView.bounds = pickerRect; [pickerView release]; [menu release]; But … Read more

Limiting UIDatePicker dates from a particular time. Such as Input DOB to a restricted age limit

You can use dateByAddingUnit and subtract 16 years from current date to set the maximum date for your datePicker as follow: datePicker.maximumDate = NSCalendar.currentCalendar().dateByAddingUnit(.Year, value: -16, toDate: NSDate(), options: []) Xcode 10.2.1 • Swift 5 datePicker.maximumDate = Calendar.current.date(byAdding: .year, value: -16, to: Date())