Monday 29 February 2016

Set date of a Date Picker in Objective C


datepicker.png
In objective C, UIDatePicker is the best way to display date and time options. We can set date of our choice in a Date picker. Also we can set minimum and maximum date.
Here I am creating UIDatePicker first.
  1.       UIDatePicker *pickerDate=[[UIDatePicker alloc]initWithFrame:pickerFrame];
  2.       pickerDate.datePickerMode=UIDatePickerModeDateAndTime;
We can set limits also. Here is the code:-
  1. //Here I am setting 1 Hour interval to the current date.
  2.       NSDate *date = [NSDate dateWithTimeInterval:3600.0 sinceDate:[NSDate date]];
  3.       [pickerDate setMaximumDate:date];
  4.       [pickerDate setMinimumDate:pickerDate.date];
Here is the code to add time in seconds to set the interval.

No comments:

Post a Comment