UIPickerView Height not changeable [duplicate]

∥☆過路亽.° 提交于 2019-11-27 02:51:02

问题


I'm trying to change PickerView's height

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

Xcode log shows the following message:

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

How can I change its height?


回答1:


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

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

Example:

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

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

Refer more here.




回答2:


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

More detail.




回答3:


There are only three valid values 162.0, 180.0 and 216.0 for height of the UIPicker. even if you set different height it will set the height to the one of the these three heights which is nearest to your given height.




回答4:


Try like this. I also googled so many examples and found this one.

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


来源:https://stackoverflow.com/questions/12473566/uipickerview-height-not-changeable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!