HOW TO FIT DATEPICKER INTO UIACTIONSHEET IN IOS

Tarun Kumar

Total Post:214

Points:1642
Posted by  Tarun Kumar
 747  View(s)
Ratings:
Rate this:

I have created an applicaiton on iPhone, now I want to fit UIDatePicker into the UIActionSheet. I have created a button to show actionSheet. 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 *actionSheet = [[UIActionSheet alloc] initWithTitle:

@"Date Picker"
                               delegate:self
                      cancelButtonTitle:@"Cancel"
                 destructiveButtonTitle:nil
                       otherButtonTitles:nil];

// Add the picker
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDate;
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];

[pickerView release];
[actionSheet release];

I also try with some other code like this:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithFrame:CGRectMake(150.0, 150.0, 70.0f, 70.0f)];

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

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to fit datepicker into UIActionSheet in iOS

    I get a solution of my code that I asked we can solve this like that:

        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                                      delegate:self
                             cancelButtonTitle:@"Cancel"
                        destructiveButtonTitle:nil
                             otherButtonTitles:nil];
        // Add the picker
        UIDatePicker *pickerView = [[UIDatePicker alloc] init];
        pickerView.datePickerMode = UIDatePickerModeDate;
        [actionSheet addSubview:pickerView];
        [actionSheet showInView:self.view]; 
        [actionSheet setBounds:CGRectMake(0,0,220, 400)];

        CGRect pickerRect = pickerView.bounds;
        pickerRect.origin.y = -100;
        pickerView.bounds = pickerRect;

        [pickerView release];
        [actionSheet release];

    But it will better to create a fullscreen view with a UIDatePicker and a navigation bar. For an example see UICatalog -> Pickers sample from the iPhone DevCenter.

      Modified On Dec-15-2015 12:17:11 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!