You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
6.5 KiB
180 lines
6.5 KiB
// |
|
// DurationTimeTableViewCell.m |
|
// tongxin |
|
// |
|
// Created by WeiChaoZheng on 2018/7/4. |
|
// Copyright © 2018年 xTT. All rights reserved. |
|
// |
|
|
|
#import "DurationTimeTableViewCell.h" |
|
#define StartTAG 8090 |
|
#define EndTAG 8091 |
|
|
|
@implementation DurationTimeTableViewCell |
|
|
|
- (void)awakeFromNib { |
|
[super awakeFromNib]; |
|
// Initialization code |
|
[UICommon ui_uiViewFillet:CGRectMake(0, 0, ScreenWidth-30, 112) Viewdirection:PYUIdirectionTop toView:self sizeMake:12]; |
|
//取消 输入回调 |
|
self.aTitleLabel.font = DefineFontSize; |
|
self.startTextField.font = FontBold_(32); |
|
self.endTextField.font = FontBold_(32); |
|
self.endTextField.tintColor = [UIColor clearColor]; |
|
self.startTextField.tintColor = [UIColor clearColor]; |
|
[self.aTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.contentView).offset(20); |
|
make.top.equalTo(self.contentView).offset(17); |
|
}]; |
|
|
|
[self.line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(self.contentView); |
|
make.top.equalTo(self.contentView).offset(75); |
|
make.size.mas_equalTo(self.line.size); |
|
}]; |
|
|
|
[self.startTextField mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(self.line); |
|
make.right.equalTo(self.line.mas_left).inset(Adapted(30)); |
|
make.size.mas_equalTo(self.startTextField.size); |
|
}]; |
|
|
|
[self.endTextField mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(self.line); |
|
make.left.equalTo(self.line.mas_right).offset(Adapted(30)); |
|
make.size.mas_equalTo(self.endTextField.size); |
|
}]; |
|
|
|
UIImageView *line = [UIImageView new]; |
|
line.backgroundColor = RGB(240, 240, 240); |
|
[self.contentView addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.contentView).inset(15); |
|
make.bottom.equalTo(self.contentView.mas_bottom); |
|
make.height.mas_equalTo(0.5); |
|
}]; |
|
|
|
[self.startTextField addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventEditingChanged]; |
|
[self.endTextField addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventEditingChanged]; |
|
self.selectionStyle = UITableViewCellSelectionStyleNone; |
|
} |
|
|
|
|
|
|
|
|
|
- (void)timeInputViewWithModel:(UIDatePickerMode)mode WithTextField:(UITextField*)textField WithDate:(NSDate *)nowDate{ |
|
textField.textAlignment = NSTextAlignmentRight; |
|
|
|
// textField.layer.cornerRadius = 15; |
|
// textField.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
// textField.layer.borderWidth = 1; |
|
// textField.textAlignment = 1; |
|
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; |
|
if([textField isEqual:self.startTextField]){ |
|
datePicker.tag = StartTAG; |
|
}else{ |
|
datePicker.tag = EndTAG; |
|
} |
|
|
|
if (@available(iOS 13.4, *)) { |
|
datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; |
|
} |
|
|
|
datePicker.datePickerMode = mode; |
|
datePicker.date = nowDate; |
|
// datePicker.datePickerMode = UIDatePickerModeTime; |
|
[datePicker addTarget:self |
|
action:@selector(cellClick:) |
|
forControlEvents:UIControlEventValueChanged]; |
|
|
|
textField.inputView = datePicker; |
|
[self.contentView bringSubviewToFront:textField.inputView]; |
|
} |
|
|
|
- (void)cellClick:(id)sender{ |
|
UITextField *textField = sender; |
|
if (self.durationBlock) { |
|
if ([sender isKindOfClass:[UITextField class]]) { |
|
|
|
|
|
if (textField.keyboardType == UIKeyboardTypePhonePad) { |
|
NSString *tmp = textField.text; |
|
|
|
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-"] invertedSet]; |
|
textField.text = [[tmp componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; |
|
} |
|
self.durationBlock(textField.text, [textField isEqual:self.startTextField]); |
|
return; |
|
} |
|
|
|
if([sender isKindOfClass:[UIDatePicker class]]){ |
|
UIDatePicker * datePic = (UIDatePicker*)sender; |
|
NSString *text; |
|
if (datePic.datePickerMode == UIDatePickerModeTime){ //时间 |
|
text = [myHelper getDateFormatWithStr:@"HH:mm" |
|
date:[datePic date]]; |
|
}else if (datePic.datePickerMode == UIDatePickerModeDate){//日期 |
|
text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" |
|
date:[datePic date]]; |
|
} |
|
if(datePic.tag == StartTAG){ |
|
self.startTextField.text = text; |
|
self.durationBlock(text, YES); |
|
}else{ |
|
self.endTextField.text = text; |
|
self.durationBlock(text, NO); |
|
} |
|
|
|
} |
|
|
|
} |
|
} |
|
|
|
#pragma mark UITextFieldDelegate |
|
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{ |
|
NSString *text = [NSString stringWithFormat:@"%@%@",textField.text,string]; |
|
|
|
if ((self.regularStr.length > 0) && ![self validateNumber:text]) { |
|
return NO; |
|
} |
|
return YES; |
|
} |
|
|
|
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ |
|
if ([textField.inputView isKindOfClass:[UIDatePicker class]]) { |
|
NSString *text ; |
|
UIDatePicker *datePicker = (UIDatePicker *)textField.inputView; |
|
|
|
if (datePicker.datePickerMode == UIDatePickerModeTime){ //时间 |
|
text = [myHelper getDateFormatWithStr:@"HH:mm" |
|
date:[datePicker date]]; |
|
|
|
}else if (datePicker.datePickerMode == UIDatePickerModeDate){//日期 |
|
text = [myHelper getDateFormatWithStr:@"yyyy-MM-dd" |
|
date:[datePicker date]]; |
|
|
|
} |
|
textField.text = text; |
|
if (self.durationBlock) { |
|
self.durationBlock(text, [textField isEqual:self.startTextField]); |
|
} |
|
} |
|
|
|
return YES; |
|
} |
|
|
|
#pragma mark 正则表达式判断 |
|
-(BOOL)validateNumber:(NSString *)text |
|
{ |
|
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",self.regularStr]; |
|
return [numberPre evaluateWithObject:text]; |
|
} |
|
|
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { |
|
[super setSelected:selected animated:animated]; |
|
|
|
// Configure the view for the selected state |
|
} |
|
|
|
@end
|
|
|