views:

64

answers:

1

I have a UIPickerView with a variable number of components to display. In its contoller i have this -pickerView:withForComponent:

- (CGFloat)pickerView:(UIPickerView *)pv widthForComponent:(NSInteger)component {
    CGFloat f;
    if (component == 0) {
        f = 30;

    } else {
        if ([componentsData count]>2) {
            f = 260.0/([componentsData count]-1);
        } else{
            f = 260.0;
        }
    } 
    return f;
}

this works fine if I call [pickerView reloadAllComponents], but how could I extend a components width if it is touched (and of course shrink all others)?

+1  A: 

To do this, even if your picker options are all text, you'll have to use

pickerView:viewForRow:forComponent:reusingView:

You'll basically need to generate an array of UIViews for your picker options, and retain them in an array. Then, when a row is selected, expand that UIView directly, and iterate through the array, contracting the others accordingly.

DougW