2022-07-19GYTimeSelectPicker

//  时间选择器

#import

typedefvoid(^GYTimeSelectPickerBlock) (NSString*timeString);

@interface GYTimeSelectPicker : UIView<UIPickerViewDelegate,UIPickerViewDataSource>

@property(nonatomic, strong)UIButton *deteBut;

@property(nonatomic, strong)UIButton *cancalBut;

@property(nonatomic, strong)GYTimeSelectPickerBlock timeBlock;

/*  初始化方法

    frame :选择框的frame

    arrData : 要展示的数据

*/

- (instancetype)initWithFrame:(CGRect)framestartTime:(NSString*)starTimeendTime:(NSString*)endTime;

@end


#import "GYTimeSelectPicker.h"

#define PickerHeight240

@interface GYTimeSelectPicker()

//时间可是为“2018-06-13 19:30”形式。

@property(nonatomic, strong)NSString *starTime;//开始时间

@property(nonatomic, strong)NSString *endTime;//结束时间

@property (nonatomic, strong)UIPickerView *pickerView;

@property (nonatomic, strong)NSMutableArray *yearArray;

@property (nonatomic, strong)NSMutableArray *monthArray;

@property (nonatomic, strong)NSMutableArray *monthMutableArray;

@property (nonatomic,strong)NSMutableArray *endMonthArr;

@property (nonatomic, strong)NSMutableArray *dayArray;

@property (nonatomic, strong)NSMutableArray *dayMutableArray;

@property (nonatomic, strong)NSMutableArray *endDayArr;

@property (nonatomic, strong)NSMutableArray *hourArray;

@property (nonatomic, strong)NSMutableArray *hourMutableArray;

@property (nonatomic, strong)NSMutableArray *endHourArr;

@property(nonatomic, strong)NSMutableArray *pointArray;

@property(nonatomic, strong)NSMutableArray *pointMutableArray;

@property(nonatomic, strong)NSMutableArray *endPointArr;

@end

@implementation GYTimeSelectPicker{

    intyear;

    intendYear;

    intmonth;

    intendMonth;

    intday;

    intendDay;

    inthour;

    intendHour;

    intpoint;

    intendPoint;


    NSString*currentMonthString;


    NSInteger m;


    NSIntegerselectedYearRow;

}

- (instancetype)initWithFrame:(CGRect)framestartTime:(NSString*)starTimeendTime:(NSString*)endTime{

    self= [superinitWithFrame:frame];

    if(self)

    {

        [self setBackgroundColor:[UIColor whiteColor]];

        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

        self.starTime= starTime;

        self.endTime= endTime;

        [selfinitCtrl];

        [selfaddTime];

    }

    return self;

}

-(void)initCtrl

{

    self.backgroundColor = [UIColor clearColor];

    UIButton *bgButton = [[UIButton alloc ] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

    [bgButtonaddTarget:self action:@selector(onButtonCancel) forControlEvents:UIControlEventTouchUpInside];

    bgButton.backgroundColor=RGBA(0,0,0,0.2);

    [selfaddSubview:bgButton];


    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-PickerHeight, SCREEN_WIDTH, PickerHeight)];

    bgView.backgroundColor = [UIColor whiteColor];

    [selfaddSubview:bgView];


    UIButton *btnCancel = [[UIButton alloc ] initWithFrame:CGRectMake(0, 0, 80, 40)];

    [btnCancelsetTitle:@"取消" forState:UIControlStateNormal];

    [btnCancelsetTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];

    [btnCanceladdTarget:self action:@selector(onButtonCancel) forControlEvents:UIControlEventTouchUpInside];

    [bgViewaddSubview:btnCancel];


    UILabel *selectLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 0, SCREEN_WIDTH-160, 40)];

    selectLabel.text=@"请选择";

    selectLabel.font = [UIFont systemFontOfSize:15];

    selectLabel.textColor=UIColorFromRGB(0x333333);

    selectLabel.textAlignment = NSTextAlignmentCenter;

    [bgViewaddSubview:selectLabel];


    UIButton *btnFinish = [[UIButton alloc ] initWithFrame:CGRectMake(self.frame.size.width-80, 0, 80, 40)];

    [btnFinishsetTitle:@"完成" forState:UIControlStateNormal];

    [btnFinishsetTitleColor:UIColorFromRGB(UI_COLOR_Exam_Red) forState:UIControlStateNormal];

    [btnFinishaddTarget:self action:@selector(onButtonFinish) forControlEvents:UIControlEventTouchUpInside];

    [bgViewaddSubview:btnFinish];


    _pickerView = [[UIPickerView alloc ] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH,PickerHeight-40)];

    _pickerView.delegate = self;

    _pickerView.dataSource = self;

    [_pickerView setBackgroundColor:[UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1.0]];

    [bgViewaddSubview:_pickerView];

}

- (void)viewTap:(UITapGestureRecognizer *)tap{


}

-(void) onButtonCancel

{

    if(self)

    {

        [self removeFromSuperview];

    }

}

-(void) onButtonFinish

{

    NSString*time;

    intcomponent0 = (int)[self.pickerViewselectedRowInComponent:0];

    intcomponent1 = (int)[self.pickerViewselectedRowInComponent:1];

    intcomponent2 = (int)[self.pickerViewselectedRowInComponent:2];

//    int component3 = (int)[self.pickerView selectedRowInComponent:3];

//    int component4 = (int)[self.pickerView selectedRowInComponent:4];


    intselectedMon;

    NSMutableArray*selectedMonArr;

    if(component0 ==0&&component0 !=self.yearArray.count-1) {

        selectedMon = [self.monthMutableArray[component1]intValue];

        selectedMonArr = [self.monthMutableArraymutableCopy];

    }elseif(component0 ==self.yearArray.count-1){

        selectedMon = [self.endMonthArr[component1]intValue];

        selectedMonArr = [self.endMonthArrmutableCopy];

    }else{

        selectedMon = [self.monthArray[component1]intValue];

        selectedMonArr = [self.monthArraymutableCopy];

    }

    //年

    time = [NSStringstringWithFormat:@"%@",self.yearArray[component0]];

    //月

    if(component0 ==0&& component0 !=self.yearArray.count-1) {

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.monthMutableArray[component1]];

    }elseif(component0 ==self.yearArray.count-1){

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.endMonthArr[component1]];

    }else

    {

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.monthArray[component1]];;

    }

    //日

    if(component0==0&component1==0&&!(component0 ==self.yearArray.count-1&component1==selectedMonArr.count-1)) {

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.dayMutableArray[component2]];


    }elseif(component0 ==self.yearArray.count-1&component1==selectedMonArr.count-1){

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.endDayArr[component2]];

    }else{

        time =  [NSStringstringWithFormat:@"%@-%@",time,self.dayArray[component2]];

    }

//    //小时

//    if (component0==0 &component1==0&&component2==0&&!(component0 == self.yearArray.count - 1 &&component1==self.endMonthArr.count-1  &&component2==self.endDayArr.count-1)) {

//        time =  [NSString stringWithFormat:@"%@ %@",time,self.hourMutableArray[component3]];

//    }else if(component0 == self.yearArray.count - 1 &&component1==self.endMonthArr.count-1  &&component2==self.endDayArr.count-1){

//        time =  [NSString stringWithFormat:@"%@ %@",time,self.endHourArr[component3]];

//    }else{

//        time =  [NSString stringWithFormat:@"%@ %@",time,self.hourArray[component3]];

//    }

//    //分

//    if (component0==0 &component1==0&&component2==0&&component3==0&&!(component0 == self.yearArray.count - 1 &&component1==self.endMonthArr.count-1  &&component2==self.endDayArr.count-1 && component3 == self.endHourArr.count - 1)) {

//        time =  [NSString stringWithFormat:@"%@:%@",time,self.pointMutableArray[component4]];

//    }else if(component0 == self.yearArray.count - 1 &&component1==self.endMonthArr.count-1  &&component2==self.endDayArr.count-1 && component3 == self.endHourArr.count - 1){

//        time =  [NSString stringWithFormat:@"%@:%@",time,self.endPointArr[component4]];

//    }else{

//        time =  [NSString stringWithFormat:@"%@:%@",time,self.pointArray[component4]];

//    }


    if(self.timeBlock){

       self.timeBlock(time);

    }

    //点击完成后,关闭当前view

    [self onButtonCancel];

}

- (void)addTime{


    //NSDate *date = [NSDate date];


    NSDateFormatter *formatterS = [[NSDateFormatter alloc]init];


    [formatterSsetDateFormat:@"yyyy-MM-dd HH:mm:ss"];

     NSDate*starDate = [formatterSdateFromString:self.starTime];

     NSDate*endDate = [formatterSdateFromString:self.endTime];


    NSComparisonResultresult = [starDatecompare:endDate];


    if(result ==NSOrderedDescending) {

        NSLog(@"传入的时间  结束时间应 大于开始时间");

        return;

    }


    // Get Current Year


    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

    [formattersetDateFormat:@"yyyy"];


    NSString *currentyearString = [NSString stringWithFormat:@"%@",

                                   [formatterstringFromDate:starDate]];

    year=[currentyearStringintValue];

    NSString *endyearString = [NSString stringWithFormat:@"%@",

                               [formatterstringFromDate:endDate]];

    endYear= [endyearStringintValue];



    // Get Current  Month


    [formattersetDateFormat:@"MM"];


    currentMonthString = [NSString stringWithFormat:@"%ld",(long)[[formatter stringFromDate:starDate]integerValue]];

    month=[currentMonthString intValue];


    NSString *endMonthString =[NSString stringWithFormat:@"%ld",(long)[[formatter stringFromDate:endDate]integerValue]];

    endMonth= [endMonthStringintValue];


    // Get Current  Date


    [formattersetDateFormat:@"dd"];

    NSString*currentDateString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:starDate]];

    day=[currentDateStringintValue];

    NSString*endDateString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:endDate]];

    endDay=[endDateStringintValue];



    [formattersetDateFormat:@"HH"];

    NSString*currentHourString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:starDate]];

    hour= [currentHourStringintValue];

    NSString*endHourString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:endDate]];

    endHour= [endHourStringintValue];



    [formattersetDateFormat:@"mm"];

    NSString*currentPointString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:starDate]];

    point= [currentPointStringintValue];

    NSString*endPointString = [NSStringstringWithFormat:@"%@",[formatterstringFromDate:endDate]];

    endPoint= [endPointStringintValue];



    self.yearArray = [NSMutableArray array];


    self.monthArray = [NSMutableArray array];

    self.monthMutableArray = [NSMutableArray array];

    self.endMonthArr = [NSMutableArray array];


    self.dayMutableArray = [NSMutableArray array];

    self.dayArray = [NSMutableArray array];

    self.endDayArr = [NSMutableArray array];


    self.hourArray = [NSMutableArray array];

    self.hourMutableArray = [NSMutableArray array];

    self.endHourArr = [NSMutableArray array];


    self.pointArray = [NSMutableArray array];

    self.pointMutableArray = [NSMutableArray array];

    self.endPointArr = [NSMutableArray array];

    //年

    for(inti =0; i <=endYear-year; i ++) {

        NSString*yearString = [NSStringstringWithFormat:@"%d",year+ i];

        [self.yearArrayaddObject:yearString];

    }


    //月份

    if(endYear==year){

        for(intt=month;t<=endMonth;t++){

            NSString*endyearmonth = [NSStringstring];

            if(t <10) {

                endyearmonth = [NSStringstringWithFormat:@"0%d",t];

            }else{

                endyearmonth = [NSStringstringWithFormat:@"%d",t];

            }

            [self.endMonthArraddObject:endyearmonth];

        }

    }else{

        for(intj=month; j <=12; j ++) {

            NSString*yearmonth = [NSStringstring];

            if(j <10) {

                yearmonth = [NSStringstringWithFormat:@"0%d",j];

            }else{

                yearmonth = [NSStringstringWithFormat:@"%d",j];

            }


            [self.monthMutableArrayaddObject:yearmonth];

        }

        for(intt=1;t<=endMonth;t++){

            NSString*endyearmonth = [NSStringstring];

            if(t <10) {

                endyearmonth = [NSStringstringWithFormat:@"0%d",t];

            }else{

                endyearmonth = [NSStringstringWithFormat:@"%d",t];

            }

            [self.endMonthArraddObject:endyearmonth];

        }


        for(intj=1; j <=12; j ++) {

            NSString*yearmonth = [NSStringstring];

            if(j <10) {

                yearmonth = [NSStringstringWithFormat:@"0%d",j];

            }else{

                yearmonth = [NSStringstringWithFormat:@"%d",j];

            }

            [self.monthArrayaddObject:yearmonth];

        }

    }

    //天

    if(endYear == year && month == endMonth){

        for(intt =day;t<=endDay;t++){

            NSString*enddayString = [NSStringstring];

            if(t <10) {

                enddayString = [NSStringstringWithFormat:@"0%d",t];

            }else{

                enddayString = [NSStringstringWithFormat:@"%d",t];

            }

            [self.endDayArraddObject:enddayString];

        }

    }else{

        for(inti =1; i <=31; i++)

        {  NSString*dayString = [NSStringstring];

            if(i <10) {

                dayString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                dayString = [NSStringstringWithFormat:@"%d",i];

            }

            [self.dayArrayaddObject:dayString];


        }

        for(inti =day; i <=31; i++)

        {

            NSString*dayString = [NSStringstring];

            if(i <10) {

                dayString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                dayString = [NSStringstringWithFormat:@"%d",i];

            }


            [self.dayMutableArrayaddObject:dayString];

        }

        for(intt =1;t<=endDay;t++){

            NSString*enddayString = [NSStringstring];

            if(t <10) {

                enddayString = [NSStringstringWithFormat:@"0%d",t];

            }else{

                enddayString = [NSStringstringWithFormat:@"%d",t];

            }

            [self.endDayArraddObject:enddayString];

        }

    }


    //小时

    if(endYear == year && month == endMonth && day == endDay){

        for(intt =hour;t<=endHour;t++){

            NSString*endhourString = [NSStringstring];

            if(t <10) {

                endhourString = [NSStringstringWithFormat:@"0%d",t];

            }else{

                endhourString = [NSStringstringWithFormat:@"%d",t];

            }


            [self.endHourArraddObject:endhourString];

        }

    }else{

        for(inti =0; i <=23; i++)

        {  NSString*hourString = [NSStringstring];

            if(i <10) {

                hourString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                hourString = [NSStringstringWithFormat:@"%d",i];

            }

            [self.hourArrayaddObject:hourString];


        }

        for(inti =hour; i <=23; i++)

        {

            NSString*hourString = [NSStringstring];

            if(i <10) {

                hourString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                hourString = [NSStringstringWithFormat:@"%d",i];

            }


            [self.hourMutableArrayaddObject:hourString];

        }

        for(intt =0;t<=endHour;t++){

            NSString*endhourString = [NSStringstring];

            if(t <10) {

                endhourString = [NSStringstringWithFormat:@"0%d",t];

            }else{

                endhourString = [NSStringstringWithFormat:@"%d",t];

            }


            [self.endHourArraddObject:endhourString];

        }

    }


    //分钟

    if(endYear == year && month == endMonth && day == endDay){

        for(inti =point; i <=endPoint; i++)

        {

            NSString*pointString = [NSStringstring];

            if(i <10) {

                pointString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                pointString = [NSStringstringWithFormat:@"%d",i];

            }


            [self.endPointArraddObject:pointString];

        }

    }else{

        for(inti =0; i <=59; i++)

        {  NSString*pointString = [NSStringstring];

            if(i <10) {

                pointString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                pointString = [NSStringstringWithFormat:@"%d",i];

            }

            [self.pointArrayaddObject:pointString];


        }

        for(inti =point; i <=59; i++)

        {

            NSString*pointString = [NSStringstring];

            if(i <10) {

                pointString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                pointString = [NSStringstringWithFormat:@"%d",i];

            }


            [self.pointMutableArrayaddObject:pointString];

        }

        for(inti =0; i <=endPoint; i++)

        {

            NSString*pointString = [NSStringstring];

            if(i <10) {

                pointString = [NSStringstringWithFormat:@"0%d",i];

            }else{

                pointString = [NSStringstringWithFormat:@"%d",i];

            }


            [self.endPointArraddObject:pointString];

        }

    }



}

#pragma mark ------------ pickViewDelegate ------------

- (void)pickerView:(UIPickerView*)pickerViewdidSelectRow:(NSInteger)rowinComponent:(NSInteger)component

{

    m=row;


    if(component ==0)

    {

        selectedYearRow= row;

        [self.pickerView reloadAllComponents];

    }

    elseif(component ==1)

    {

        //selectedMonthRow = row;

        [self.pickerView reloadAllComponents];

    }

    elseif(component ==2)

    {

        //selectedDayRow = row;

        [self.pickerView reloadAllComponents];


    }elseif(component ==3){

        //selectedHourRow = row;

        [self.pickerView reloadAllComponents];

    }


}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return3;

}

// returns the # of rows in each component..

- (NSInteger)pickerView:(UIPickerView*)pickerViewnumberOfRowsInComponent:(NSInteger)component{

    if(component ==0) {//年

        returnself.yearArray.count;

    }

    if(component ==1) {//月

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];


        if(selectRow ==0&&selectRow !=self.yearArray.count-1) {

            return[self.monthMutableArraycount];

        }elseif(selectRow ==self.yearArray.count-1){

            return[self.endMonthArrcount];

        }else

        {

            return[self.monthArraycount];

        }

    }

    if(component ==2) {//天


        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];


        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        intselectedMon;

        NSMutableArray*selectedMonArr;

        if(selectRow ==0&& selectRow !=self.yearArray.count-1) {

            selectedMon = [self.monthMutableArray[selectRow1]intValue];

            selectedMonArr = [self.monthMutableArraymutableCopy];

        }elseif(selectRow ==self.yearArray.count-1){

            selectedMon = [self.endMonthArr[selectRow1]intValue];

            selectedMonArr = [self.endMonthArrmutableCopy];

        }else{

            selectedMon = [self.monthArray[selectRow1]intValue];

             selectedMonArr = [self.monthArraymutableCopy];

        }

        if(selectRow ==0&& selectRow !=self.yearArray.count-1&& selectRow1==0) {

            //全选第一个row

            if(selectedMon ==1|| selectedMon ==3|| selectedMon ==5|| selectedMon ==7|| selectedMon ==8|| selectedMon ==10|| selectedMon ==12)

            {

            returnself.dayMutableArray.count;

            }elseif(selectedMon ==2)

            {

                intyearint = [[self.yearArrayobjectAtIndex:selectedYearRow]intValue];


                if(((yearint %4==0)&&(yearint %100!=0))||(yearint %400==0)){

                    returnself.dayMutableArray.count-2;

                }

                else

                {

                    returnself.dayMutableArray.count-3;// or return 29

                }

            }

            else

            {

                returnself.dayMutableArray.count-1;

            }

        }elseif(selectRow ==self.yearArray.count-1&& selectRow1==selectedMonArr.count-1){

                returnself.endDayArr.count;

        }else{

            //不是最后一个row  也 不是第一个row

            if(selectedMon ==1|| selectedMon ==3|| selectedMon ==5|| selectedMon ==7|| selectedMon ==8|| selectedMon ==10|| selectedMon ==12)

            {

                return31;

            }

            elseif(selectedMon ==2)

            {

                intyearint = [[self.yearArrayobjectAtIndex:selectedYearRow]intValue];


                if(((yearint %4==0)&&(yearint %100!=0))||(yearint %400==0)){

                    return29;

                }

                else

                {

                    return28;// or return 29

                }

            }

            else

            {

                return30;

            }

        }


    }

    if(component ==3) {//小时

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];

        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        NSIntegerselectRow2 =  [pickerViewselectedRowInComponent:2];

        if(selectRow ==0&&selectRow1==0  &&selectRow2==0&&!(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1&&selectRow2==self.endDayArr.count-1)) {

            returnself.hourMutableArray.count;

        }elseif(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1){

            returnself.endHourArr.count;

        }else{

            returnself.hourArray.count;

        }

    }

    if(component ==4) {//分钟

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];

        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        NSIntegerselectRow2 =  [pickerViewselectedRowInComponent:2];

        NSIntegerselectRow3 =  [pickerViewselectedRowInComponent:3];

        if(selectRow ==0&&selectRow1==0  &&selectRow2==0&& selectRow3 ==0&&!(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1&& selectRow3 ==self.endHourArr.count-1)) {

            return self.pointMutableArray.count;

        }elseif(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1&& selectRow3 ==self.endHourArr.count-1){

            returnself.endPointArr.count;

        }else{

            returnself.pointArray.count;

        }

    }

    return0;

}

- (UIView*)pickerView:(UIPickerView*)pickerViewviewForRow:(NSInteger)rowforComponent:(NSInteger)componentreusingView:(UIView*)view{

    UILabel*pickerLabel = (UILabel*)view;

    if(pickerLabel ==nil) {

        CGRectframe =CGRectMake(0.0,0.0,60,50);

        pickerLabel = [[UILabelalloc]initWithFrame:frame];

        [pickerLabelsetTextAlignment:NSTextAlignmentCenter];

        [pickerLabelsetBackgroundColor:[UIColor clearColor]];

        [pickerLabelsetFont:[UIFont systemFontOfSize:16]];


    }


    if(component ==0)

    {

        pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.yearArray[row] ,@"年"];// Year

    }

    if(component ==1)

    {

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];

        if(selectRow ==0&& selectRow !=self.yearArray.count-1) {

            pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.monthMutableArray[row] ,@"月"];


        }elseif(selectRow ==self.yearArray.count-1){

             pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.endMonthArr[row] ,@"月"];

        }else

        {

            pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.monthArray[row] ,@"月"];


        }

    }

    if(component ==2)

    {

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];


        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        intselectedMon;

        NSMutableArray*selectedMonArr;

        if(selectRow ==0&&selectRow !=self.yearArray.count-1) {

            selectedMon = [self.monthMutableArray[selectRow1]intValue];

            selectedMonArr = [self.monthMutableArraymutableCopy];

        }elseif(selectRow ==self.yearArray.count-1){

            selectedMon = [self.endMonthArr[selectRow1]intValue];

            selectedMonArr = [self.endMonthArrmutableCopy];

        }else{

            selectedMon = [self.monthArray[selectRow1]intValue];

            selectedMonArr = [self.monthArraymutableCopy];

        }


        if(selectRow==0&selectRow1==0&&!(selectRow ==self.yearArray.count-1&selectRow1==selectedMonArr.count-1)) {

            pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.dayMutableArray[row] ,@"日"];


        }elseif(selectRow ==self.yearArray.count-1&selectRow1==selectedMonArr.count-1){

            //全选最后一个row

            pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.endDayArr[row] ,@"日"];

        }else{

            pickerLabel.text=  [NSStringstringWithFormat:@"%@%@",self.dayArray[row] ,@"日"];


        }



    }

    if(component ==3) {

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];

        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        NSIntegerselectRow2 =  [pickerViewselectedRowInComponent:2];

        if(selectRow ==0&&selectRow1==0  &&selectRow2==0&&!(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1)) {

            pickerLabel.text=[NSStringstringWithFormat:@"%@时",self.hourMutableArray[row]];

        }elseif(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1){

             pickerLabel.text=[NSStringstringWithFormat:@"%@时",self.endHourArr[row]];

        }else{

            pickerLabel.text=[NSStringstringWithFormat:@"%@时",self.hourArray[row]];

        }

    }

    if(component ==4) {

        NSIntegerselectRow =  [pickerViewselectedRowInComponent:0];

        NSIntegerselectRow1 =  [pickerViewselectedRowInComponent:1];

        NSIntegerselectRow2 =  [pickerViewselectedRowInComponent:2];

        NSIntegerselectRow3 =  [pickerViewselectedRowInComponent:3];


        if(selectRow ==0&&selectRow1==0  &&selectRow2==0&& selectRow3 ==0&&!(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1&& selectRow3 ==self.endHourArr.count-1)) {

            pickerLabel.text=[NSStringstringWithFormat:@"%@分",self.pointMutableArray[row]];

        }elseif(selectRow ==self.yearArray.count-1&&selectRow1==self.endMonthArr.count-1  &&selectRow2==self.endDayArr.count-1&& selectRow3 ==self.endHourArr.count-1){

            pickerLabel.text= [NSStringstringWithFormat:@"%@分",self.endPointArr[row]];

        }else{

            pickerLabel.text= [NSStringstringWithFormat:@"%@分",self.pointArray[row]];

        }

    }

    returnpickerLabel;

}

- (CGFloat)pickerView:(UIPickerView*)pickerViewrowHeightForComponent:(NSInteger)component{

    return35;

}

@end

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,290评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,399评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,021评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,034评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,412评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,651评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,902评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,605评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,339评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,586评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,076评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,400评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,060评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,851评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,685评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,595评论 2 270

推荐阅读更多精彩内容