自己修改了一下第三方UUDatePicker_Block,添加了屏幕适配,并解决了崩溃的bug
使用如下- (void)myTap{ [myBackView removeFromSuperview];}- (void)tap{ [_textView resignFirstResponder]; if (myBackView) { [myBackView removeFromSuperview]; } myBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-64)]; myBackView.backgroundColor = [UIColor colorWithWhite:0 alpha:.2]; [self.view addSubview:myBackView]; UITapGestureRecognizer *myTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(myTap)]; [myBackView addGestureRecognizer:myTap]; dateTimePickerView = [[UUDatePicker alloc]initWithframe:CGRectMake(0, screenHeight-64-200, screenWidth, 200) PickerStyle:UUDateStyle_YearMonthDayHourMinute didSelected:^(NSString *year, NSString *month, NSString *day, NSString *hour, NSString *minute, NSString *weekDay) { selectTimeStr = [NSString stringWithFormat:@"%@-%@-%@ %@:%@",year,month,day,hour,minute]; }]; dateTimePickerView.minLimitDate = [[NSDate date]dateByAddingTimeInterval:0];//也可以自定义最小时间// // HH是24进制,hh是12进制// formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";// // 返回的格林治时间// NSDate *date2 = [formatter dateFromString:@"2017-2-23 12:14:56"];// dateTimePickerView.minLimitDate = date2; [myBackView addSubview:dateTimePickerView]; UIView *whiteV = [[UIView alloc]initWithFrame:CGRectMake(0, dateTimePickerView.top-30, screenWidth, 30)]; whiteV.backgroundColor = [UIColor whiteColor]; [myBackView addSubview:whiteV]; // UIButton *cancleBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 5, 60,30)]; cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [cancleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [cancleBtn setBackgroundColor:dark_green]; [cancleBtn setTitle:@"取消" forState:UIControlStateNormal]; [cancleBtn addTarget:self action:@selector(selectedButtons:) forControlEvents:UIControlEventTouchUpInside]; cancleBtn.tag = 100; [self setRadios:YES View:cancleBtn]; [whiteV addSubview:cancleBtn]; // UIButton *okBtn = [[UIButton alloc]initWithFrame:CGRectMake(screenWidth-70, 5, 60, 30)]; [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; okBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [okBtn setBackgroundColor:dark_green]; [okBtn setTitle:@"确定" forState:UIControlStateNormal]; [okBtn addTarget:self action:@selector(selectedButtons:) forControlEvents:UIControlEventTouchUpInside]; okBtn.tag = 101; [self setRadios:YES View:okBtn]; [whiteV addSubview:okBtn]; }-(void)setRadios:(BOOL)bl View:(UIView *)vw{ if (bl) { vw.layer.cornerRadius=4; vw.layer.masksToBounds = YES; }}- (void)selectedButtons:(UIButton *)btn{ if (btn.tag==100) { [myBackView removeFromSuperview]; } if (btn.tag==101) { [myBackView removeFromSuperview]; _timelbl.text = selectTimeStr; }}