How to customise the UIPickerView height

此生再无相见时 提交于 2019-12-21 20:28:24

问题


How to Customise the height of UIPickerView more then 250 . i have done the following but unable to get the height as given

 -(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];

    }

回答1:


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



来源:https://stackoverflow.com/questions/29816101/how-to-customise-the-uipickerview-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!