可修改文字颜色和限制最大日期的时间选择器使用示例。
PGDatePicker.zip。
使用代码:
@interface CBPHealthCareViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITextFieldDelegate,UIGestureRecognizerDelegate,PGDatePickerDelegate>
PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init]; datePickManager.confirmButtonTextColor = BGColorHex(FF7648); datePickManager.cancelButtonTextColor = BGColorHex(CCCCC); datePickManager.headerViewBackgroundColor = BGColorHex(F0F0F0); datePickManager.isShadeBackground = true; PGDatePicker *datePicker = datePickManager.datePicker; datePicker.textColorOfSelectedRow = BGColorHex(FF7648); datePicker.lineBackgroundColor = BGColorHex(FF7648); datePicker.delegate = self; datePicker.datePickerType = PGDatePickerTypeVertical; datePicker.isHiddenMiddleText = false; // datePicker.isCycleScroll = true; datePicker.datePickerMode = PGDatePickerModeDate; long long nowTime = (long long)([[NSDate date] timeIntervalSince1970]*1000+[[BITSingleObject sharedInstance] getZoneTimeDifference])+[BITSingleObject sharedInstance].localServerDifferenceTime-24*3600*1000-8*3600*1000; datePicker.maximumDate = [NSDate dateWithTimeIntervalSince1970:nowTime/1000]; datePicker.originDate = [NSDate dateWithTimeIntervalSince1970:nowTime/1000]; [self presentViewController:datePickManager animated:false completion:nil];
#pragma PGDatePickerDelegate - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents { NSString *date_time = [NSString stringWithFormat:@"%d-%d-%d", dateComponents.year,dateComponents.month,dateComponents.day]; // 日期格式化类 NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; // 设置日期格式(为了转换成功) fmt.dateFormat = @"yyyy-MM-dd"; // NSString * -> NSDate * NSDate *date = [fmt dateFromString:date_time]; NSDateFormatter *dateFmt = [[NSDateFormatter alloc]init]; dateFmt.dateFormat = @"yyyy-MM-dd"; self.model.thirdHealthCareEntity.date_time = [dateFmt stringFromDate:date]; NSLog(@"dateComponents = %@, self.model.thirdHealthCareEntity.date_time:%@", dateComponents, self.model.thirdHealthCareEntity.date_time); self.healthCareSelectTool.model = self.model.thirdHealthCareEntity; self.model.status = GBCommonStatusThird; self.model.page = 1; self.model.thirdHealthCareEntity.is_old = YES; [self excuteParent_health_listCommand]; }