自定义UIDatePikerView

1、添加文件GoYearMonthDayPickerView.h .m .xib、NSDate+Helper.h .m、iCarousel.h .m

2、在Lable上显示日期

UILabel *ageLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 0, 150, 58)];
ageLabel.tag = 105;
ageLabel.text = @"1985-12-29";
ageLabel.textColor = [UIColor whiteColor];
ageLabel.textAlignment = NSTextAlignmentRight;
ageLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapAgeLabel = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(GetDateAction:)];
[ageLabel addGestureRecognizer:tapAgeLabel];
[self.view addSubview:ageLabel];

- (void)GetDateAction:(UITapGestureRecognizer *)tap{
    NSLog(@"tap = %ld",tap.numberOfTouches);
    GOYearMonthDayPickerBox *box = [GOYearMonthDayPickerView yearMonthDayPickerBoxWithPickerDelegate:self];//定义视图窗口
    [box.yearMonthDayPicker show];//显示
}

#pragma mark -  GOYearMonthDayPickerViewDelegate 
- (void)yearMonthDayPicker:(GOYearMonthDayPickerView *)picker selectedYear:(int)year selectedMonth:(int)month selectedDay:(int)day
{
    UILabel *ageLabel = (UILabel *)[self.view viewWithTag:105];
    ageLabel.text = [NSString stringWithFormat:@"%d-%02d-%02d",year,month,day];
}

  

posted @ 2015-03-09 14:18  沙漠只容绿洲  阅读(142)  评论(0编辑  收藏  举报