UIPickerView高度不可更改

8

我想要改变PickerView的高度。

self.pickerView = [[UIPickerView alloc] init];
self.pickerView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
-[UIPickerView setFrame:]: invalid height value 274.0 pinned to 216.0 

我该如何改变它的高度?

你不能改变UIPickerView的高度。 - Romit M.
在iOS 9上,一切都改变了!https://dev59.com/2HRB5IYBdhLWcg3wn4QL#35562894 - Dan Rosenstark
4个回答

30

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

以上代码将picker视图的height更改为一半,并将其re-position到确切的(Left-x1,Top-y1)位置。

请在此处查看更多。


3

UIPickerView只有三种有效的高度(162.0、180.0和216.0)。

更多细节。


1

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


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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接