开发者

Extend PickerViews Component while touching

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)?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜