Reputation: 68
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.
Upvotes: 3
Views: 3732
Reputation: 8424
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));
Upvotes: 0
Reputation: 14118
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.
Upvotes: 0
Reputation: 1752
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
.
Upvotes: -1
Reputation: 4001
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!
Upvotes: 2