3

Is there a way to change the number of displayed rows in a UIPickerView from 5 to 4? The height of the picker doesn't seem to be adjustable in IB and i can't find any delegate methods to control this.

Please note that I'm asking about the number of displayed rows, not the number of rows in the component.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gerry Koh
  • 68
  • 1
  • 6

4 Answers4

2

You can set the height of the rows in a UIPickerview using the following UIPickerViewDelegate method

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
  return 60.0f;
}

I'm not sure of the exact height you'd need to get four rows displaying. Might just have to fiddle with that until you get it right!

James Zaghini
  • 3,895
  • 4
  • 45
  • 61
  • thanks! the issue that i'm having is i'm trying to design to a comp using images as the rows. i'm using this method already to match the height of the images. the issue is that i'm trying to reduce the vertical height of the entire picker component so that i'm showing 4 rows with each row at the specified height. – Gerry Koh Mar 30 '13 at 02:32
0

There is not direct way given by Apple, which allows us to change UIPickerView height using setFrame.

But there are two way-arounds to achive the same:

Hope this will be helpful to you.

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96
0

you cannot mess up alot with uipickerview height, reason being once you change the height you have to readjust each of the row size and the font for each of the row so that they are displayed clearly and separately. There are only three valid heights for UiPickerview (162.0, 180.0 and 216.0). However you can change the height by the following

CGAffineTransform t0 = CGAffineTransformMakeTranslation (0, mypickview.bounds.size.height/2);
CGAffineTransform s0 = CGAffineTransformMakeScale       (1.0, 0.5);
CGAffineTransform t1 = CGAffineTransformMakeTranslation (0, -mypickview.bounds.size.height/2);
mypickview.transform = CGAffineTransformConcat          (t0, CGAffineTransformConcat(s0, t1));
hariszaman
  • 8,202
  • 2
  • 40
  • 59
-1

If you want to set height of the UIPickerView then you can use :

picketView.transform = CGAffineTransformMakeScale(1, 0.70);

Above code will scale the UIPickerView.

Yashesh
  • 1,799
  • 1
  • 11
  • 29