UIDatePicker Inside UIActionSheet

Suppose You have to open UIDatePicker Inside UIActionSheet on click Event inside the UITextField 

– (void)textFieldDidBeginEditing:(UITextField *)textField

UIDatePicker *  datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];

datePicker.datePickerMode = UIDatePickerModeDate;

NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@”yyyy-dd-MM “];

datePicker.hidden = NO;

datePicker.date = [NSDate date];

datePicker.minimumDate = datePicker.date;


UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

pickerToolbar.barStyle = UIBarStyleBlackOpaque;

[pickerToolbar sizeToFit];


NSMutableArray *barItems = [[NSMutableArray alloc] init];


UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self     action:@selector(doneButtonPressed:)];

[barItems addObject:doneBtn];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];


[barItems addObject:cancelBtn];

[pickerToolbar setItems:barItems animated:YES];

[actionSheet addSubview:pickerToolbar];

[actionSheet addSubview:datePicker];

[actionSheet showInView:self.view];

[actionSheet setBounds:CGRectMake(0,0,320, 475)];




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s