CustomDatePopupView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.delegate = self;
  30. _txtYear.keyboardType = UIKeyboardTypeNumberPad;
  31. _txtYear.returnKeyType = UIReturnKeyNext;
  32. _txtMonth.delegate = self;
  33. _txtMonth.keyboardType = UIKeyboardTypeNumberPad;
  34. _txtMonth.returnKeyType = UIReturnKeyNext;
  35. _txtDay.delegate = self;
  36. _txtDay.keyboardType = UIKeyboardTypeNumberPad;
  37. _txtDay.returnKeyType = UIReturnKeyDone;
  38. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  39. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  40. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  41. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  42. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  43. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  44. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  45. // [self setTitle:@"정답 날짜 입력"];
  46. }
  47. }
  48. return self;
  49. }
  50. - (void)setTitle:(NSString *)title {
  51. self.lblTitle.text = title;
  52. }
  53. - (void)didMoveToSuperview {
  54. if (!self.superview) {
  55. return;
  56. }
  57. _txtYear.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  58. _txtMonth.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  59. _txtDay.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  60. }
  61. - (IBAction)btnConfirmTouched:(id)sender {
  62. // NSLog(@"확인");
  63. [super btnConfirmTouched:sender];
  64. }
  65. #pragma mark - CustomTextField
  66. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  67. if ([textField isEqual:_txtDay]) {
  68. [self btnConfirmTouched:nil];
  69. }
  70. if ([textField isEqual:_txtMonth]) {
  71. [_txtDay becomeFirstResponder];
  72. }
  73. if ([textField isEqual:_txtYear]) {
  74. [_txtMonth becomeFirstResponder];
  75. }
  76. return YES;
  77. }
  78. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  79. if ([textField isEqual:_txtYear]) {
  80. if (textField.text.length >= 4 && range.length == 0) {
  81. return NO;
  82. }
  83. }
  84. else {
  85. if (textField.text.length >= 2 && range.length == 0) {
  86. return NO;
  87. }
  88. }
  89. return YES;
  90. }
  91. @end