// // DateSelectPopupView.m // OneCable // // Created by nComz on 2017. 4. 11.. // Copyright © 2017년 ntels. All rights reserved. // #import "JDObject.h" #import "CustomLabel.h" #import "CustomButton.h" #import "CustomDatePopupView.h" @interface CustomDatePopupView () { } @end @implementation CustomDatePopupView - (id)initWithTitle:(NSString *)title { [self setTitle:title]; return [self initFromNib]; } - (id)initFromNib { for (UIView *view in [CommonUtil nibViews:@"CustomDatePopupView"]) { if ([view isKindOfClass:[CustomDatePopupView class]]) { self = (CustomDatePopupView *)view; //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함. self.frame = [UIScreen mainScreen].bounds; NSArray *arrToday = [[CommonUtil currentDate] explode:@"."]; _txtYear.delegate = self; _txtYear.keyboardType = UIKeyboardTypeNumberPad; _txtYear.returnKeyType = UIReturnKeyNext; _txtMonth.delegate = self; _txtMonth.keyboardType = UIKeyboardTypeNumberPad; _txtMonth.returnKeyType = UIReturnKeyNext; _txtDay.delegate = self; _txtDay.keyboardType = UIKeyboardTypeNumberPad; _txtDay.returnKeyType = UIReturnKeyDone; [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)]; [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)]; [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)]; [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)]; [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)]; [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal]; [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal]; // [self setTitle:@"정답 날짜 입력"]; } } return self; } - (void)setTitle:(NSString *)title { self.lblTitle.text = title; } - (void)didMoveToSuperview { if (!self.superview) { return; } _txtYear.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView; _txtMonth.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView; _txtDay.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView; } - (IBAction)btnConfirmTouched:(id)sender { // NSLog(@"확인"); [super btnConfirmTouched:sender]; } #pragma mark - CustomTextField - (BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isEqual:_txtDay]) { [self btnConfirmTouched:nil]; } if ([textField isEqual:_txtMonth]) { [_txtDay becomeFirstResponder]; } if ([textField isEqual:_txtYear]) { [_txtMonth becomeFirstResponder]; } return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([textField isEqual:_txtYear]) { if (textField.text.length >= 4 && range.length == 0) { return NO; } } else { if (textField.text.length >= 2 && range.length == 0) { return NO; } } return YES; } @end