CKT
CKT

Reputation: 1217

How to change the size of Date Picker in iphone app?

I have a requirement to use date picker in my applicaiton. I have lot of controlles in my view that..i cannot add the date picker with the default size. Can anyone please suggest me that how can I reduce the size of the picker? i tried it with Ib, but size option is disabled in IB?

Upvotes: 4

Views: 8337

Answers (5)

Minna
Minna

Reputation: 2561

You can change tha size of picker view using CGAffineTransform. Create a new UIView and apply transform. then add the picker view to the new UIView. Then add this to your main view.

UIView* transformView = [[UIView alloc] initWithFrame:CGRectMake(75.0f, 344.0f, self.pickerView.frame.size.width, self.pickerView.frame.size.height)];
    transformView.transform = CGAffineTransformMakeScale(0.60f, 0.60f);
    [transformView addSubview:self.pickerView];
    [self.view addSubview:transformView]; 

But aacording to Apple's documentation,

A picker is a generic version of the date picker. As with a date picker, users spin the wheel (or wheels) of a picker until the value they want appears. The overall size of a picker, including its background, is fixed at the same size as the keyboard on iPhone.

Link: https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW1

Upvotes: 1

Manjunath
Manjunath

Reputation: 4555

Use setFrame:(CGRect)inRect API of Picker view in viewDidLoad method. But I don't know whether you can resize DatePicker!!!

Upvotes: 1

Vladimir
Vladimir

Reputation: 170849

If you create UIPickerView in your code then you can use -initWithFrame to set its frame explicitly (see this question) - in the answer provided there stated that some "visual glitches" may appear with this approach.

As a second option you can adjust picker's frame by applying appropriate CGAffineTransform to it ( I have not tested it much but it seems to work fine):

picker.transform = CGAffineTransformMake(0.5, 0, 0, 0.5, -80, 0);

This (somewhat dummy) code scales UIPickerView to a half size and applies translation to place the picker to the left side of the screen. You can play with different transform values to get the effect you want.

Edit: The code above works for UIDatePickerView as well (sorry was not attentive to a question). But as other stated Apple had not made picker's frame (easily) customizable so it may mean that you should consider changing your design to try to use the picker in its proper size to conform to Apple's HIG.

Upvotes: 3

AlexVogel
AlexVogel

Reputation: 10621

You can change the size of your datepicker with changing the frame of the DatepIcker, but this will clip most of the datepicker and is not a good idea. Try to add your datepicker in a modal view instead.

Upvotes: 4

Massimo Cafaro
Massimo Cafaro

Reputation: 25429

To the best of my knowledge, you can't.

Upvotes: 2

Related Questions