Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 322
CKT Avatar asked Dec 23 '22 04:12

CKT


2 Answers

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.

like image 132
AlexVogel Avatar answered Jan 09 '23 16:01

AlexVogel


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.

like image 25
Vladimir Avatar answered Jan 09 '23 14:01

Vladimir