CustomDatePopupView.m 3.9 KB

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