views:

1460

answers:

6

I've only seen it in a VERY few iPhone apps... but it looks like a picker that rotates left/right (instead of top/bottom).

They usually put it on 1 line of a tableView... to allow the user to quickly pick between a small number of choices (like 3-10).

How is that coded?

A: 

Have you ever considered taking a table view and rotating it?

Didn't think so. Go try that. :)

Sneakyness
I probably wouldn't want to rotate the entire table-view.(And have the "rows" going top-to-bottom on the screen.) But... maybe the developers are rotating the picker... and some how resizing it down to fit in 1 row of the table-view. But what would the code look like?
Donna
Why don't you try and write it and find out for yourself? That's the only way you're going to learn anything.
Sneakyness
I would strongly suggest reading through all of Apple's documentation at http://developer.apple.com in the iPhone section on getting started, both with iPhone programming and Objective-C.
Sneakyness
So the answer to my question is "go find out yourself"? Or to read 1000s of pages of docs... *NONE* of which say anything about "horizontal pickers"? Wow. Thanks. We really don't need stackoverflow.com at all... everyone should just go solve everything on their own.
Donna
It's only 3 short booklets. It took me about two weeks to read through all of them, really read them, and understand them. Because I read through those things, I knew exactly what I wanted to do when I wanted to make something like a sideways picker. (Sideways UIPicker? Horizontal UIPicker?)
Sneakyness
Also I'm specifically harsh on you in this case because from your evident lack of example failures, I can see you haven't even tried anything, which leads me to believe you're being lazy.
Sneakyness
3 short booklet? False.Took you 2 weeks to read them?(I just don't have time to read WEEKS worth of info... for 1 question.) So this forum is just to call people 'lazy' when they ask questions?Wow.Moderator: Please delete Sneakyness's account. He just posts insulting/useless remarks towards everyone trying to learn something here.
Donna
The point I'm trying to make here is that if you would have spent the time to read these books in the first place (like every beginning iPhone developer should), you wouldn't have even had to come here to ask the question.
Sneakyness
@Sneakyness not everyone has the time to devote to Cocoa that you might. Be considerate of others situations. The whole point of SO.com is that people have questions, and we either 1) know the answer or 2) know how to find it. Telling somebody to RTFM is almost never the best answer. ;)
Dave DeLong
A: 

Try a paged scrollview that has the items you want on one per page, and perhaps overlay an image above it if you want nicer graphics for your control, and only allow for horizontal scrolling (don't make the contentSize of the scrollview taller than the size of the actual view, and disable vertical scroll bouncing on the control).

Kevlar
+2  A: 

You can do this by taking a regular UIPickerView, adjusting its width (via setFrame:), and then applying an NSAffineTransform to rotate it 90º. You'll then need to rotate each item in the picker 90º the other way.

It's a little tedious to do it properly, but it can be done.

Dave DeLong
Won't the letters also turn by 90 degrees? I think it is a custom view on the screenshot.
Alex
@Alex yes, which is why you need to rotate each `viewForRow:forComponent:reusingView:` by 90º the other way.
Dave DeLong
+3  A: 

Continuing the answer by Dave DeLong I got it working like this......

In viewDidLoad i did this...

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

Hope this helps

Madhup
For CGAffineTransform dont forget to add QuartzCore Framework to your project
Madhup
can you explain the 3.14159/2 ? (i know its PI, but why is it here and why the /2)?
Nir Levy
i did it so that picker is rotated by 90 degrees hence it will scroll horizontally and 3.14159/2 is the value of 90 degrees in radiance
Madhup
A: 

i am not getting the Horizontal Picker...Dont know the exact Problem

i am not getting the text in the picker....

i am using the same code :

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

Please help me

thank you

Mrudula
A: 

Try this-> Create Plain UIVew of size of UIPickerview, add picker on it. set numberOfComponentsInPickerView = 1. set componant width. Then add small sub views on it to Hide rest of picker. Only rotating wheel of componant should visible. Transform plain view to rotate it through 90 degree.

Make sure to apply tranform in:

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

}

Now you can add palin view as a subview for horizontal picker on any view.

atrane