如何自定义UIPickerView的高度? [英] How to customise UIPickerView height?

查看:55
本文介绍了如何自定义UIPickerView的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自定义UIPickerView的高度?我希望它高到250以上.

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

推荐答案

这里的UIPickerView只有三个有效高度(162.0、180.0和216.0).

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

您可以使用 CGAffineTransformMakeTranslation CGAffineTransformMakeScale 函数来使选择器正确使用,以方便您使用.

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

示例:

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) );

上面的代码将选取器视图的高度更改为一半,然后将其重新放置到确切的位置(左x1,上y1).

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

在此处参考更多.如何更改UIPickerView高度

这篇关于如何自定义UIPickerView的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆