0

I want a UIPickerView in following design;

http://dl.dropbox.com/u/53051470/Screen%20shot%202012-04-18%20at%2012.02.36%20PM.png (sorry as a new user, can't paste image here)

I read other questions on same topic too, and try to implement pickerView:viewForRow:forComponent:reusingView: method as well, but din't get the actual results;

Requirements are like selected value should display in green bar with checkmark image, and in white color; Moreover when user will start scrolling the picker, any value that enters inside green bar should turns into green color, and any value that leaves the green bar ares should turns into black;

Any suggestion?

Kind regards;

Ans
  • 3,461
  • 3
  • 23
  • 24

2 Answers2

0

you should use the method

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

and decide which row is highlight

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{   
        // i use a UILabel instead of your **custom UIView** , you may add a tick in you custom view

        UILabel *testRow = view?(UILabel *)view:[[[UILabel alloc] initWithFrame:CGRectMake(0,0, 140, 40)] autorelease];
        testRow.font = [UIFont fontWithName:[testArray objectAtIndex:row] size:16];
        testRow.text = [fontsArray objectAtIndex:row];
        testRow.backgroundColor = [UIColor clearColor];

        if ( row == selectedRow )
        {
            testRow.backgroundColor = [UIColor greenColor];
        }

        return testRow;
}

don't forget set the showsSelectionIndicator to NO

pickView.showsSelectionIndicator = NO;
adali
  • 5,977
  • 2
  • 33
  • 40
0

UIPickerView multiple-selection-behavior without adding other views in front of the pickerview,using: https://github.com/alexleutgoeb/ALPickerView

Improvements are highly appreciated!

Hardik Patel
  • 116
  • 2
  • 18
  • I think I'm not talking about multiple-selection-behavior of UIPickerView; If your mentioned library can create a picker with required design, post some sample code from there; – Ans Apr 19 '12 at 05:41
  • you download code from that link in the upper left of that library the zip file is available. – Hardik Patel Apr 19 '12 at 06:13