我只在非常少的iPhone应用程序中看到它......但它看起来像是左/右旋转的拾取器(而不是顶部/底部)。
他们通常把它放在tableView的1行上......允许用户在少数选择之间快速选择(如3-10)。
如何编码?
答案 0 :(得分:6)
继续Dave DeLong的回答我得到了这样的工作......
在viewDidLoad
我这样做了......
CGRect frame = horizontalPickerView.frame;
frame.size.width = 50;
frame.size.height = 216;
frame.origin.x=90;
frame.origin.y = 200;
horizontalPickerView.frame = frame;
horizontalPickerView.transform = CGAffineTransformMakeRotation(3.14159/2);
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *lbl = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)] autorelease];
lbl.transform = CGAffineTransformMakeRotation(-3.14159/2);
lbl.text = @"hi";
return lbl;
}
希望这有帮助
答案 1 :(得分:6)
Here你会找到Picker的源代码,它是水平对齐的。
答案 2 :(得分:3)
您可以通过使用常规UIPickerView,调整其宽度(通过setFrame:
),然后应用NSAffineTransform将其旋转90º来完成此操作。然后,您需要以另一种方式旋转拾取器中的每个项目。
正确地做这件事有点乏味,但可以做到。
答案 3 :(得分:1)
UIPickerView
时,@ Madhup的代码引导我走向我想要的大方向,但后来我意识到问题并没有真正解决,所以对于那些正在寻找更合适答案的人来说从左到右旋转。我读过的答案中的代码都是为了从左向右滑动,导致选择器将更高值的标签/行推到视图的左侧。这里的任何方式都是我的贡献:
在viewDidLoad
方法中:
yourPickerView.frame = frame;
yourPickerView.transform = CGAffineTransformMakeRotation(4.71238898); //Instead of rotating clockwise 90° we're rotating 90° counterclockwise. 4.71238898 being ≈270° in radians.
[self.view addSubview:self.picker];
self.yourPickerView.delegate = self;
self.yourPickerView.dataSource = self;
self.yourPickerView.showsSelectionIndicator = YES;
self.yourPickerView.userInteractionEnabled = YES;
pickerView
的方法:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)] autorelease];
yourLabel.transform = CGAffineTransformMakeRotation(1.57079633); //Instead of rotating counterclockwise 90° we're rotating 90° clockwise 1.57079633 being ≈90° in radians.
yourLabel.font = [UIFont fontWithName:@"System-Bold" size:18]; //Your font here.
yourLabel.text = @"yourLabel's text"; //or like me [NSString stringWithFormat:@"%@, [yourArray objectAtIndex:row]]
yourLabel.backgroundColor = [UIColor clearColor];
return label;
}
答案 4 :(得分:0)
尝试一个分页滚动视图,每个页面上有一个你想要的项目,如果你想为你的控件提供更好的图形,可能覆盖它上面的图像,并且只允许水平滚动(不要制作滚动视图的contentSize)高于实际视图的大小,并禁用控件上的垂直滚动弹跳。)
答案 5 :(得分:0)
试试这个 - > 创建大小为UIPickerview的Plain UIVew,在其上添加选择器。 set numberOfComponentsInPickerView = 1。 设置组件宽度。 然后在其上添加小的子视图以隐藏其余的选择器。只能看到组件的旋转轮。 转换普通视图将其旋转90度。
确保在以下位置应用转换:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *lbl = nil;
if(view)
{
lbl = (UILabel *) [view viewWithTag:11];
}
else
{
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
lbl = [[UILabel alloc] initWithFrame:CGRectMake(1, 0, 30, 30)];
lbl.tag = 11;
lbl.backgroundColor = [UIColor clearColor];
lbl.textAlignment = UITextAlignmentCenter;
lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
lbl.transform = CGAffineTransformRotate(lbl.transform, M_PI +M_PI/2);
[view addSubview:lbl];
[lbl release];
}
lbl.text = [dataSourceArray objectAtIndex:row];
return view;
}
现在,您可以将palin视图添加为任何视图上水平选择器的子视图。
答案 6 :(得分:-13)
你有没有考虑过观看桌面并旋转它?
不这么认为。去试试吧。 :)