views:

377

answers:

3

Hi all,

I am trying to scroll the picker view horizontally and this is my code.

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

But the problem is I am not able to change the width of picker view more than 216.0 if I try to do this there is a black background left.

CorrectImage this is the correct image

Now if I do this

CGRect frame = horizontalPickerView.frame;
                frame.size.width = 50;
                frame.size.height = 300;
                frame.origin.x=120;
                frame.origin.y = 200;
                horizontalPickerView.frame = frame;

                horizontalPickerView.transform = CGAffineTransformMakeRotation(3.14159/2);

I get this image

I have seen the apps like Seelibrity in which the picker has the width to fit the screen. Please help me to get out of this problem?

A: 

I don't think this is the right way... u set View Orientation to landscape and everything will follow..

Quakeboy
A: 

Hi Madhup!!

Try the following:

Open your xib file with the option "open as" -> "Pain text file"

search for the picker view object:

<object class="IBUIPickerView" id="648806599">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{0, 83}, {100, 50}}</string>  ---> here
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<bool key="IBUIShowsSelectionIndicator">YES</bool>
</object>

Change the NSframe, maybe this can help.

Regards

Alejandra!!

Alejandra
+2  A: 

UIPickerView is very sensitive to changes in height, so directly altering its frame or applying a transform to the UIPickerView leads to rendering artifacts. The only reliable way that I know of for resizing a UIPickerView is to place it within a transparent UIView, then apply a scaling (and rotation, in your case) transform to that holder view.

I provide an example of this in this answer.

Brad Larson
or he COULD use a UIScrollView.
Matt S.
A UITableView would be a better choice, given that the data source and cell displaying methods already exist. A UIScrollView would require him to reinvent the wheel for a lot of what the UIPickerView does. Even using a UITableView would require a lot of custom artwork and overlaid subviews, as well as some mechanism for managing the currently selected row.
Brad Larson