CustomDatePopupView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // DateSelectPopupView.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 11..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "CustomDatePopupView.h"
  12. @interface CustomDatePopupView () <CustomTextFieldDelegate>
  13. {
  14. }
  15. @end
  16. @implementation CustomDatePopupView
  17. - (id)initWithTitle:(NSString *)title
  18. {
  19. [self setTitle:title];
  20. return [self initFromNib];
  21. }
  22. - (id)initFromNib {
  23. for (UIView *view in [CommonUtil nibViews:@"CustomDatePopupView"]) {
  24. if ([view isKindOfClass:[CustomDatePopupView class]]) {
  25. self = (CustomDatePopupView *)view;
  26. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  27. self.frame = [UIScreen mainScreen].bounds;
  28. NSArray *arrToday = [[CommonUtil currentDate] explode:@"."];
  29. _txtYear.keyboardType = UIKeyboardTypeNumberPad;
  30. _txtYear.returnKeyType = UIReturnKeyNext;
  31. _txtMonth.keyboardType = UIKeyboardTypeNumberPad;
  32. _txtMonth.returnKeyType = UIReturnKeyNext;
  33. _txtDay.keyboardType = UIKeyboardTypeNumberPad;
  34. _txtDay.returnKeyType = UIReturnKeyDone;
  35. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  37. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  38. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  39. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  40. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  41. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  42. // [self setTitle:@"정답 날짜 입력"];
  43. }
  44. }
  45. return self;
  46. }
  47. - (void)setTitle:(NSString *)title {
  48. self.lblTitle.text = title;
  49. }
  50. - (void)didMoveToSuperview {
  51. if (!self.superview) {
  52. return;
  53. }
  54. }
  55. - (IBAction)btnConfirmTouched:(id)sender {
  56. [super btnConfirmTouched:sender];
  57. [self.delegate dismissPopupView];
  58. }
  59. - (IBAction)btnCancelTouched:(id)sender {
  60. [super btnCancelTouched:nil];
  61. [self.delegate dismissPopupView];
  62. }
  63. #pragma mark - textfield delegate
  64. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  65. if ([textField isEqual:_txtYear]) {
  66. if (textField.text.length >= 4 && range.length == 0) {
  67. return NO;
  68. }
  69. }
  70. else {
  71. if (textField.text.length >= 2 && range.length == 0) {
  72. return NO;
  73. }
  74. }
  75. return YES;
  76. }
  77. - (void)moveToPrevField:(id)sender {
  78. UITextField *tf = sender;
  79. NSInteger tag = tf.tag;
  80. if ( ![tf isEqual:_txtYear] ) {
  81. UITextField *prevTf = [self viewWithTag:tag - 1] ;
  82. [prevTf becomeFirstResponder] ;
  83. }
  84. }
  85. - (void)moveToNextField:(id)sender {
  86. UITextField *tf = sender;
  87. NSInteger tag = tf.tag;
  88. if ( ![tf isEqual:_txtDay] ) {
  89. UITextField *prevTf = [self viewWithTag:tag + 1] ;
  90. [prevTf becomeFirstResponder] ;
  91. }
  92. }
  93. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  94. [textField becomeFirstResponder];
  95. }
  96. @end