UIPickerView高度不可更改

时间:2012-09-18 08:56:41

标签: iphone ios frame uipickerview

我正在尝试更改PickerView的高度

self.pickerView = [[UIPickerView alloc] init];
self.pickerView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);

Xcode日志显示以下消息:

-[UIPickerView setFrame:]: invalid height value 274.0 pinned to 216.0 

如何更改高度?

4 个答案:

答案 0 :(得分:30)

three valid只有heights UIPickerView (162.0, 180.0 and 216.0)

您可以使用CGAffineTransformMakeTranslationCGAffineTransformMakeScale功能为您提供方便的选择。

示例:

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

上述代码change height picker view to halfre-position (Left-x1, Top-y1)位置。

请参阅here

答案 1 :(得分:3)

UIPickerView (162.0, 180.0 and 216.0)只有三个有效高度。

More detail.

答案 2 :(得分:1)

UIPicker的高度只有三个有效值162.0,180.0和216.0。即使你设置了不同的高度,它也会将高度设置为这三个高度中的一个,这个高度最接近你给定的高度。

答案 3 :(得分:0)

试试这样。我也搜索了很多例子并找到了这个例子。

pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,250,320,230)];//to change the height
pickerView.delegate =self;
pickerView.dataSource =self;
pickerView.showsSelectionIndicator = YES;
[self.view addSubview:pickerView];