xcode 如何自定义 UIPickerView 高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29816101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to customise UIPickerView height?
提问by Nischal Hada
How can I customise the height of a UIPickerView? I would like it to be taller more than 250.
如何自定义 UIPickerView 的高度?我希望它比 250 高。
I have done the following but I'm unable to set the given height.
我已完成以下操作,但无法设置给定的高度。
-(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];
}
回答by aBilal17
Here there are only three valid heights for UIPickerView (162.0, 180.0 and 216.0).
这里 UIPickerView 只有三个有效高度(162.0、180.0 和 216.0)。
You can use the CGAffineTransformMakeTranslationand CGAffineTransformMakeScalefunctions to properly fit the picker to your convenience.
您可以使用CGAffineTransformMakeTranslation和CGAffineTransformMakeScale函数来根据您的方便适当地调整选择器。
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.
上面的代码将选择器视图的高度更改为一半,并将其重新定位到准确的 (Left-x1, Top-y1) 位置。
Refer more here. How to change UIPickerView height
在这里参考更多。 如何更改 UIPickerView 高度