is there a uipickerview delegate method like scrollviewDidScroll?

后端 未结 5 480
情歌与酒
情歌与酒 2020-12-11 05:59

I have a customized UIPickerview and I do not want to use a datepicker. I want to implement the feature where when a user scrolls down/up the hours, the AM/PM component swi

5条回答
  •  眼角桃花
    2020-12-11 06:58

    have to use this two UIPickerView delegate method for event:

    DID END SCROLL:

    - (void)pickerView:(UIPickerView *)pV didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        NSLog(@"pickerView didSelectRow %zd",row);
        // DID END SCROLL: CALL YOUR HEANDLER METHOD!!
    }
    

    WILL START SCROLLING:

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
        // WILL START SCROLLING: CALL YOUR HEANDLER METHOD!!
        UILabel* label = (UILabel*)view;
        if (!label){
            label = [UILabel new];
            [label setFrame:frame];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont fontWithName:FONT_QUICKSAND_BOLD size:12]];
            [label setTextAlignment:NSTextAlignmentRight];
            [label setLineBreakMode:NSLineBreakByTruncatingMiddle];
            [label setTextColor:UIColorFromRGB(0X2692ff)];
            }
        //Update labeltext here
        [label setText:[NSString stringWithFormat:@"row %zd",row]];
        return label;
    }
    

    obviosly except for the building of UIPickerview (firstTIME!); so u have to implement a fake didendscroll event when you finish to build you piker or ignore first willstart scroll for the visible piker row

提交回复
热议问题