|
@@ -7,7 +7,7 @@
|
|
|
//
|
|
|
|
|
|
#import "KSFullDatePicker.h"
|
|
|
-#import "NSDate+KSBaseDatePicker.h"
|
|
|
+#import "NSDate+DateDetail.h"
|
|
|
#import "NSDate+Extension.h"
|
|
|
|
|
|
|
|
@@ -99,15 +99,15 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
self.block = block;
|
|
|
self.cancleBlock = cancleBlock;
|
|
|
self.pickMode = pickMode;
|
|
|
- self.frame = CGRectMake(0, 0, kScreen_Width, kScreen_Height);
|
|
|
- self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height)];
|
|
|
- self.backView.backgroundColor = HexRGBAlpha(0x363636, 0.55f);
|
|
|
+ self.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
|
|
|
+ self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
|
|
|
+ self.backView.backgroundColor = HexRGBAlpha(0x000000, 0.6f);
|
|
|
self.date = date;
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
|
|
|
tap.delegate = self;
|
|
|
[self.backView addGestureRecognizer:tap];
|
|
|
|
|
|
- self.timeView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreen_Height, kScreen_Width, 266)];
|
|
|
+ self.timeView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, 266)];
|
|
|
self.timeView.backgroundColor = [UIColor whiteColor];
|
|
|
self.timeView.layer.masksToBounds = YES;
|
|
|
if (@available(iOS 11.0, *)) {
|
|
@@ -122,7 +122,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
self.timeView.layer.mask = maskLayer;
|
|
|
}
|
|
|
/*创建显示View*/
|
|
|
- _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, kScreen_Width, 216)];
|
|
|
+ _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, kScreenWidth, 216)];
|
|
|
_contentView.backgroundColor = [UIColor whiteColor];
|
|
|
[_timeView addSubview:_contentView];
|
|
|
|
|
@@ -131,18 +131,18 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
|
|
UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
|
|
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
|
|
|
- [cancelButton setTitleColor:HexRGB(0x666666) forState:UIControlStateNormal];
|
|
|
+ [cancelButton setTitleColor:HexRGB(0x777777) forState:UIControlStateNormal];
|
|
|
[sureButton setTitle:@"确定" forState:UIControlStateNormal];
|
|
|
[sureButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
|
|
|
- cancelButton.titleLabel.font = [UIFont systemFontOfSize:17.0f];
|
|
|
- sureButton.titleLabel.font = [UIFont systemFontOfSize:17.0f];
|
|
|
+ cancelButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
|
|
|
+ sureButton.titleLabel.font = [UIFont systemFontOfSize:16.0f];
|
|
|
|
|
|
[cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[sureButton addTarget:self action:@selector(doneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
|
- cancelButton.frame = CGRectMake(20, 10, 60, 30);
|
|
|
- sureButton.frame = CGRectMake(kScreen_Width - 80, 10, 60, 30);
|
|
|
+ cancelButton.frame = CGRectMake(10, 10, 60, 30);
|
|
|
+ sureButton.frame = CGRectMake(kScreenWidth - 70, 10, 60, 30);
|
|
|
[self.timeView addSubview:cancelButton];
|
|
|
[self.timeView addSubview:sureButton];
|
|
|
|
|
@@ -153,6 +153,11 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
titleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
[self.timeView addSubview:titleLabel];
|
|
|
+
|
|
|
+ // lineView
|
|
|
+ UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(13, 50, KPortraitWidth - 26, 1)];
|
|
|
+ lineView.backgroundColor = HexRGB(0xF2F2F2);
|
|
|
+ [self.timeView addSubview:lineView];
|
|
|
[self.backView addSubview:self.timeView];
|
|
|
[self addSubview:self.backView];
|
|
|
|
|
@@ -173,6 +178,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
}
|
|
|
|
|
|
- (void)initPickViews {
|
|
|
+
|
|
|
/*添加PickerView*/
|
|
|
NSMutableArray* tempArray1 = [[NSMutableArray alloc] initWithCapacity:0];
|
|
|
NSMutableArray* tempArray2 = [[NSMutableArray alloc] initWithCapacity:0];
|
|
@@ -192,6 +198,14 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
[self createDataSource];
|
|
|
CGRect frame = _contentView.frame;
|
|
|
CGFloat height = CGRectGetHeight(frame);
|
|
|
+
|
|
|
+ if (self.pickMode != KSDATEPICKER_MODE_YEAR) {
|
|
|
+ UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, (height - 44) / 2.0f, CGRectGetWidth(frame) , 44)];
|
|
|
+ lineView.backgroundColor = HexRGB(0xF2F2F2);
|
|
|
+ lineView.layer.cornerRadius = 8.0f;
|
|
|
+ [_contentView addSubview:lineView];
|
|
|
+ }
|
|
|
+
|
|
|
if (_pickMode == KSDATEPICKER_MODE_TIME) { // 时分秒
|
|
|
CGFloat width = CGRectGetWidth(frame) / 3.0f;
|
|
|
|
|
@@ -343,6 +357,16 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
[_contentView addSubview:self.hourPicker];
|
|
|
[_contentView addSubview:self.minutePicker];
|
|
|
}
|
|
|
+ else if (_pickMode == KSDATEPICKER_MODE_YEAR) { // 年
|
|
|
+ CGFloat width = CGRectGetWidth(frame);
|
|
|
+
|
|
|
+ UIPickerView* yearPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
|
|
|
+ [self setYearPicker:yearPickerTemp];
|
|
|
+ [yearPickerTemp setValue:[UIColor blackColor] forKey:@"textColor"];
|
|
|
+ [self.yearPicker setFrame:CGRectMake(0, 0, width, height)];
|
|
|
+
|
|
|
+ [_contentView addSubview:self.yearPicker];
|
|
|
+ }
|
|
|
[self.yearPicker setDataSource:self];
|
|
|
[self.monthPicker setDataSource:self];
|
|
|
[self.dayPicker setDataSource:self];
|
|
@@ -380,7 +404,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
- (void)cancelButtonAction:(UIButton *)sender
|
|
|
{
|
|
|
[UIView animateWithDuration:0.3f animations:^{
|
|
|
- self.timeView.frame = CGRectMake(0, kScreen_Height,kScreen_Width, 266);
|
|
|
+ self.timeView.frame = CGRectMake(0, kScreenHeight,kScreenWidth, 266);
|
|
|
} completion:^(BOOL finished) {
|
|
|
[self removeFromSuperview];
|
|
|
}];
|
|
@@ -424,6 +448,10 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
date = [NSString stringWithFormat:@"%02ld:%02ld",_hourValue,_minuteValue];
|
|
|
}
|
|
|
break;
|
|
|
+ case KSDATEPICKER_MODE_YEAR:
|
|
|
+ {
|
|
|
+ date = [NSString stringWithFormat:@"%ld",_yearValue];
|
|
|
+ }
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -433,7 +461,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
|
|
|
|
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
|
- self.timeView.frame = CGRectMake(0, self.bounds.size.height, self.bounds.size.width, 230);
|
|
|
+ self.timeView.frame = CGRectMake(0, self.bounds.size.height, self.bounds.size.width, 266);
|
|
|
} completion:^(BOOL finished) {
|
|
|
[self removeFromSuperview];
|
|
|
}];
|
|
@@ -442,7 +470,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
- (void)tapAction:(UITapGestureRecognizer *)tap
|
|
|
{
|
|
|
[UIView animateWithDuration:0.3f animations:^{
|
|
|
- self.timeView.frame = CGRectMake(0, kScreen_Height,kScreen_Width, 266);
|
|
|
+ self.timeView.frame = CGRectMake(0, kScreenHeight,kScreenWidth, 266);
|
|
|
} completion:^(BOOL finished) {
|
|
|
[self removeFromSuperview];
|
|
|
}];
|
|
@@ -458,7 +486,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
[window addSubview:self];
|
|
|
|
|
|
[UIView animateWithDuration:0.3f animations:^{
|
|
|
- self.timeView.frame = CGRectMake(0, kScreen_Height - 266, kScreen_Width, 266);
|
|
|
+ self.timeView.frame = CGRectMake(0, kScreenHeight - 266, kScreenWidth, 266);
|
|
|
} completion:^(BOOL finished) {
|
|
|
nil;
|
|
|
}];
|
|
@@ -468,6 +496,10 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
|
|
|
|
|
|
#pragma mark - UIPickerViewDataSource
|
|
|
+- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
|
|
|
+ return 46.0f;
|
|
|
+}
|
|
|
+
|
|
|
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
|
|
|
return 1;
|
|
|
}
|
|
@@ -528,15 +560,15 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
|
|
|
if (ePickerViewTagYear == pickerView.tag) {
|
|
|
self.yearValue = [[self.yearArray objectAtIndex:row] intValue];
|
|
|
- } else if(ePickerViewTagMonth == pickerView.tag){
|
|
|
+ } else if(ePickerViewTagMonth == pickerView.tag) {
|
|
|
self.monthValue = [[self.monthArray objectAtIndex:row] intValue];
|
|
|
- }else if(ePickerViewTagDay == pickerView.tag){
|
|
|
+ }else if(ePickerViewTagDay == pickerView.tag) {
|
|
|
self.dayValue = [[self.dayArray objectAtIndex:row] intValue];
|
|
|
- }else if(ePickerViewTagHour == pickerView.tag){
|
|
|
+ }else if(ePickerViewTagHour == pickerView.tag) {
|
|
|
self.hourValue = [[self.hourArray objectAtIndex:row] intValue];
|
|
|
- } else if(ePickerViewTagMinute == pickerView.tag){
|
|
|
+ } else if(ePickerViewTagMinute == pickerView.tag) {
|
|
|
self.minuteValue = [[self.minuteArray objectAtIndex:row] intValue];
|
|
|
- } else if(ePickerViewTagSecond == pickerView.tag){
|
|
|
+ } else if(ePickerViewTagSecond == pickerView.tag) {
|
|
|
self.secondValue = [[self.secondArray objectAtIndex:row] intValue];
|
|
|
}
|
|
|
if (ePickerViewTagMonth == pickerView.tag || ePickerViewTagYear == pickerView.tag) {
|
|
@@ -665,7 +697,7 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
- (void)resetDateToCurrentDate {
|
|
|
|
|
|
NSDate* nowDate = self.date;
|
|
|
- [self.yearPicker selectRow:[self.yearArray count]-100 inComponent:0 animated:YES];
|
|
|
+ [self.yearPicker selectRow:[self getYearRow:[nowDate getYear]] inComponent:0 animated:YES];
|
|
|
[self.monthPicker selectRow:[nowDate getMonth]-1 inComponent:0 animated:YES];
|
|
|
[self.dayPicker selectRow:[nowDate getDay]-1 inComponent:0 animated:YES];
|
|
|
|
|
@@ -681,6 +713,14 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
[self setSecondValue:[nowDate getSeconds]];
|
|
|
}
|
|
|
|
|
|
+- (NSInteger)getYearRow:(NSInteger)year {
|
|
|
+ NSInteger index = [self.yearArray indexOfObject:[NSString stringWithFormat:@"%zd",year]];
|
|
|
+ if (index > 0) {
|
|
|
+ return index;
|
|
|
+ }
|
|
|
+ return [self.yearArray count]-100;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark -pickerViewDelegate
|
|
|
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
|
|
|
{
|
|
@@ -690,14 +730,18 @@ typedef NS_ENUM(NSInteger, PickViewTag) {
|
|
|
pickerLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
[pickerLabel setTextAlignment:NSTextAlignmentCenter];
|
|
|
[pickerLabel setBackgroundColor:[UIColor clearColor]];
|
|
|
- [pickerLabel setFont:[UIFont systemFontOfSize:16]];
|
|
|
- [pickerLabel setTextColor:[UIColor blackColor]];
|
|
|
+ [pickerLabel setFont:[UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium]];
|
|
|
+ [pickerLabel setTextColor:HexRGB(0x333333)];
|
|
|
}
|
|
|
// Fill the label text here
|
|
|
pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
|
|
|
+ if (self.subviews.count > 0 && self.pickMode != KSDATEPICKER_MODE_YEAR) {
|
|
|
+ pickerView.subviews[1].backgroundColor = [UIColor clearColor];
|
|
|
+ }
|
|
|
return pickerLabel;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
|
|
|
if ([touch.view isDescendantOfView:self.timeView]) {
|
|
|
return NO;
|