Miles Works
Miles Works

Reputation: 639

Resizing the WIDTH of UIDatePicker

Is it possible to CHANGE the WIDTH of the UIDatePicker ?

Im trying to do this programmatically, not via storyboards...iOS 6.1

Thanks.

Miles.

Upvotes: 5

Views: 5229

Answers (3)

Puneet Kumar
Puneet Kumar

Reputation: 1

If you specify the frame when you create picker, does not work.

UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.frame.size.width - 216, self.view.frame.size.width,216)];

you can try

UIDatePicker *picker = [[UIDatePicker alloc] init];
CGRect frame = picker.frame;
frame.origin.x  = (self.frame.size.width - 320)/2;
frame.size.width = self.frame.size.width - (picker.frame.origin.x * 2);
[picker setFrame:frame];

Upvotes: 0

dcruz
dcruz

Reputation: 21

If you specify the frame when you create picker, does not work.

UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(10, 20, 300, 300)];

You should create before and then change frame:

UIDatePicker *picker = [[UIDatePicker alloc] init];
CGRect frame = picker.frame;
frame.size.width = 300;
...
[picker setFrame:frame];

Upvotes: 1

Jason Barker
Jason Barker

Reputation: 3020

Yes. It's something you would change by setting the frame property.

For example, if you wanted to increase the width of your datePicker object by 50 points:

CGRect frame = self.datePicker.frame;
frame.size.width += 50;
[self.datePicker setFrame: frame];

Upvotes: 3

Related Questions