Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitting a UIDatePicker into a UIActionSheet

I'm trying to get a UIDatePicker with a UIButton to show up in a UIActionSheet. Unfortunately it gets cropped off and the entire Date Picker is not visible. I have not even attempted to add the UIButton yet. Can anyone suggest on getting the entire view to fit properly? I'm not sure how to add the proper dimensions as UIActionSheet seems to lack an -initWithFrame: type constructor.

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];  [pickerView release]; [menu release]; 

I've also tried with something similar to:

UIActionSheet *menu = [[UIActionSheet alloc] initWithFrame:CGRectMake(200.0, 200.0, 100.0f, 100.0f)]; 

The coords are ofcourse not realistic, but they don't seem to affect the position/size of the UIActionSheet.

like image 452
Coocoo4Cocoa Avatar asked Dec 08 '08 15:12

Coocoo4Cocoa


1 Answers

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 you better create a fullscreen view with a UIDatePicker and a navigation bar. For an example see UICatalog -> Pickers sample from the iPhone DevCenter.

like image 196
thbonk Avatar answered Oct 13 '22 09:10

thbonk