如何自定义UIPickerView的高度超过250。我做了以下但无法达到给定的高度
-(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];
}
答案 0 :(得分:8)
此处UIPickerView只有三个有效高度(162.0,180.0和216.0)。
您可以使用 CGAffineTransformMakeTranslation 和 CGAffineTransformMakeScale 功能,为您提供方便的选择。
示例:
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) );
上面的代码将拾取器视图的高度更改为一半,并将其重新定位到精确(Left-x1,Top-y1)位置。