Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

ios - How do you shrink a UIPickerView on the iPhone?

I would like to reduce the height of a UIPickerView in my iPhone app, so that it shows only one row and one column. The height of the picker view should be equal to the height of a row.

I'm using Interface Builder to construct the UIPickerView, but I can't find an easy way to re-size this control.

How do you shrink a UIPickerView?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, you can slightly shrink the whole UIPickerView by applying an affine transform to an enclosing view. For example:

CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero];

pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, pickerSize.width, pickerSize.height)];
pickerTransformView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);

[pickerTransformView addSubview:pickerView];
[self.view addSubview:pickerTransformView];
[pickerTransformView release];

will scale a picker to 75% of its original size by placing it within a containing view and applying a scaling transform to that view. Applying a transform directly to the UIPickerView leads to undesirable drawing artifacts.

However, the kind of resizing you're looking for would be best served by creating a custom control.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...