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.
144 lines
4.9 KiB
144 lines
4.9 KiB
![]()
2 years ago
|
//
|
||
|
// 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
|
||
|
//取消 输入回调
|
||
|
self.aTitleLabel.font = DefineFontSize;
|
||
|
[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
|