How do you shrink a UIPickerView on the iPhone? How do you shrink a UIPickerView on the iPhone? ios ios

How do you shrink a UIPickerView on the iPhone?


Actually, you can slightly shrink the whole UIPickerView by applying an affine transform to an enclosing view. For example:

CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, pickerSize.width, pickerSize.height)];pickerTransformView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);[pickerTransformView addSubview:pickerView];[self.view addSubview:pickerTransformView];[pickerTransformView release];

will scale a picker to 75% of its original size by placing it within a containing view and applying a scaling transform to that view. Applying a transform directly to the UIPickerView leads to undesirable drawing artifacts.

However, the kind of resizing you're looking for would be best served by creating a custom control.


It is possible and easy!

Just open the nib file as plain text, then find the picker view and adjust the measures:

<object class="IBUIPickerView" id="783900772"><reference key="NSNextResponder" ref="191373211"/><int key="NSvFlags">292</int><string key="NSFrame">{{85, 68}, {150, 116}}</string>

That's all!


The answer of user2248258 actually works if you use storyboards and/or autolayout. There I would like to add screenshots as Nilambar suggested.

  1. place a pickerview in another container view with the size you want it Place a pickerview into another container view

  2. check clipSubviews for the container view

  3. align the picker centered horizontally and vertically in that container view, also give it zero constraints for the trailing and leading place

This way the picker view gets clipped off to the correct size (won't be resized).

Result:enter image description here


matomo