0

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 http://img709.imageshack.us/img709/6982/picture5g.png 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 http://img46.imageshack.us/img46/2792/picture6b.png

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?

Madhup Singh Yadav
  • 8,110
  • 7
  • 51
  • 84

2 Answers2

2

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.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • or he COULD use a UIScrollView. – Matt S. Dec 23 '09 at 20:14
  • 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 Dec 24 '09 at 22:21
0

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
  • 726
  • 3
  • 9
  • 25