How to resize Date Picker in iphone application?

I have a requirement to use date picker in my application. In my opinion, I have many controls that ... I cannot add a date picker with a default size. Can anyone suggest me how can I reduce the size of the collector? I tried it with Ib, but the size option is disabled in IB?

+4
source share
5 answers

You can resize your dumper by changing the DatepIcker frame, but this will close most of the date picker, and this is not a good idea. Try adding your datepicker in modal form.

+4
source

If you create a UIPickerView in your code, you can use -initWithFrame to explicitly set its frame (see this question ) - in the answer pointed out there that some β€œvisual crashes” may appear with this approach.

As a second option, you can adjust the selection frame by applying the appropriate CGAffineTransform to it (I have not tested it, but it seems to work fine):

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

This (somewhat dummy) code scales the UIPickerView to half the size and applies translation to put the collector on the left side of the screen. You can play with various conversion values ​​to get the desired effect.

Edit: The code above also works for UIDatePickerView (sorry, was not attentive to the issue). But since other Apple claims have not made the custom bezel (easy) customizable, so this may mean that you should consider redesigning to try to use the assembler in the proper size to fit Apple HIG.

+3
source

As far as I know, you cannot.

+2
source

Use the setFrame:(CGRect)inRect Picker setFrame:(CGRect)inRect API in the viewDidLoad method. But I do not know if you can resize DatePicker !!!

+1
source

You can resize the picker view using CGAffineTransform. Create a new UIView and apply the transform. then add the selection 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 according to Apple documentation

The picker is a general version of the date picker. As with selecting a date, users rotate the collector wheel (or wheels) until the value that they want appears. The total size of the collector, including its background, is fixed at the same size as the keyboard on the iPhone.

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

+1
source

Source: https://habr.com/ru/post/1303908/


All Articles