forum

Home / DeveloperSection / Forums / How to fit datepicker into UIActionSheet in iOS

How to fit datepicker into UIActionSheet in iOS

Tarun Kumar 1594 14-Dec-2015

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.


Updated on 15-Dec-2015

Can you answer this question?


Answer

1 Answers

Liked By