How to Shrink a Uipickerview on the Iphone

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.

How to change UIPickerView height

It seems obvious that Apple doesn't particularly invite mucking with the default height of the UIPickerView, but I have found that you can achieve a change in the height of the view by taking complete control and passing a desired frame size at creation time, e.g:

smallerPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 120.0)];

You will discover that at various heights and widths, there are visual glitches. Obviously, these glitches would either need to be worked around somehow, or choose another size that doesn't exhibit them.

How to increase picker view ( transformed pickerview ) width?

UIPickerView is very sensitive to changes in height, so directly altering its frame or applying a transform to the UIPickerView leads to rendering artifacts. The only reliable way that I know of for resizing a UIPickerView is to place it within a transparent UIView, then apply a scaling (and rotation, in your case) transform to that holder view.

I provide an example of this in this answer.

Can We resize the UIDatePicker View in iPhone

This is a commonly asked question here:

  • How to change UIPickerView height
  • UIPicker sizing in landscape mode
  • how to shrink picker view in iphone?

It's not a control that likes to be resized, but you can play some tricks with its frame or with the frame of a UIView you've placed it in. As I describe here, the cleanest way I've found to resize this control is by placing it within a hosting UIView, then applying an affine transform to scale that hosting view down.

How to change the Font size in UIPickerView?

You need to implement pickerView:viewForRow:forComponent:reusingView: method in picker's delegate

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}


Related Topics



Leave a reply



Submit