Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customise UIPickerView height?

How can I customise the height of a UIPickerView? I would like it to be taller more than 250.

I have done the following but I'm unable to set the given height.

-(void)pickerview:(id)sender
{
    pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(0,200,320,400)];
    pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
    pickerView.backgroundColor = [UIColor lightGrayColor];
    [pickerView selectRow:1 inComponent:0 animated:YES];
    [self.view addSubview:pickerView];
    // [contentView addSubview:pickerView];
}
like image 747
Nischal Hada Avatar asked Dec 08 '25 09:12

Nischal Hada


1 Answers

Here there are only three valid heights for UIPickerView (162.0, 180.0 and 216.0).

You can use the CGAffineTransformMakeTranslation and CGAffineTransformMakeScale functions to properly fit the picker to your convenience.

Example:

CGAffineTransform t0 = CGAffineTransformMakeTranslation( 0,
    pickerview.bounds.size.height/2 );
CGAffineTransform s0 = CGAffineTransformMakeScale(1.0, 0.5);
CGAffineTransform t1 = CGAffineTransformMakeTranslation( 0,
    pickerview.bounds.size.height/-2 );
pickerview.transform = CGAffineTransformConcat( t0,
    CGAffineTransformConcat(s0, t1) );

The above code change the height of picker view to half and re-position it to the exact (Left-x1, Top-y1) position.

Refer more here. How to change UIPickerView height

like image 93
aBilal17 Avatar answered Dec 10 '25 00:12

aBilal17



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!