需要在 ViewController 中显示 4 个 UIPickerView。
如何自定义高度?
我们可以给出的最小高度是 162。我可以为每个 UIPickerView 给出 100 高度吗?有没有可用的框架或示例?
需要在 ViewController 中显示 4 个 UIPickerView。
如何自定义高度?
我们可以给出的最小高度是 162。我可以为每个 UIPickerView 给出 100 高度吗?有没有可用的框架或示例?
尝试这个:
UIPickerView *picker = [[UIPickerView alloc] initWithFrame: CGRectZero];
picker.showsSelectionIndicator = YES;
picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
CGSize ps = [picker sizeThatFits: CGSizeZero];
picker.frame = CGRectMake(0.0, 0.0, ps.width, ps.height + 100);
尝试使用以下代码,它可能适用于您的情况:
self.MyPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
有关其他提示,请查看此答案
如果您不介意剪裁末端,则可以将其嵌入到较小的视图中,并启用剪裁。
因为UIPickerView
只有三个高度:162,180,216。您可以使用CGAffineTransformMakeTranslation
和CGAffineTransformMakeScale
适当地适合选择器。
CGAffineTransform t;
CGAffineTransform s;
CGAffineTransform u;
UIPickerView *pickerview;
t = CGAffineTransformMakeTranslation (0, pickerview.bounds.size.height);
s = CGAffineTransformMakeScale (1.0,0.5);
u = CGAffineTransformMakeTranslation (0 ,pickerview.bounds.size.height);
pickerview.transform = CGAffineTransformConcat (t, CGAffineTransformConcat(s,u));
上面的代码在这里改变了选择器视图的高度。