8

我正在尝试更改 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

4 回答 4

30

这里只three valid heightsUIPickerView (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)位置。

在这里参考更多。

于 2012-09-18T09:02:26.187 回答
3

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

更多详情。

于 2012-09-18T09:00:08.993 回答
1

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

于 2012-09-18T09:03:12.540 回答
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];
于 2012-09-18T09:27:13.687 回答