TemperaturePopupView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // TemperaturePopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/23/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "TemperaturePopupView.h"
  12. @implementation TemperaturePickerView
  13. - (void)awakeFromNib {
  14. self.layer.backgroundColor = [UIColor clearColor].CGColor;
  15. [self setValue:kUITextColor02 forKey:@"textColor"];
  16. }
  17. - (void)didMoveToSuperview {
  18. // if (!_changed) {
  19. // _changed = YES;
  20. // }
  21. self.showsSelectionIndicator = YES;
  22. self.subviews[1].backgroundColor = kUITextColor02;
  23. self.subviews[2].backgroundColor = kUITextColor02;
  24. }
  25. @end
  26. @interface TemperaturePopupView () <UIPickerViewDataSource, UIPickerViewDelegate> {
  27. NSMutableArray<ItemModel> *_checkedItems;
  28. NSMutableArray *_temperatureArray;
  29. }
  30. @end
  31. @implementation TemperaturePopupView
  32. @synthesize temperature = _temperature;
  33. - (id)initFromNib {
  34. for (UIView *view in [CommonUtil nibViews:@"TemperaturePopupView"]) {
  35. if ([view isKindOfClass:[TemperaturePopupView class]]) {
  36. self = (TemperaturePopupView *)view;
  37. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  38. self.frame = [UIScreen mainScreen].bounds;
  39. _temperaturePicker.dataSource = self;
  40. _temperaturePicker.delegate = self;
  41. _temperatureArray = [[NSMutableArray alloc] init];
  42. NSInteger zindex = 0, i = -50;
  43. BOOL isZeroSet = NO;
  44. while (i < 51) {
  45. if (i != 0 && !isZeroSet) {
  46. zindex++;
  47. } else if (i == 0) {
  48. isZeroSet = YES;
  49. }
  50. NSString *temperature = [NSString stringWithFormat:@"%zd", i++];
  51. [_temperatureArray addObject:temperature];
  52. }
  53. [_temperaturePicker selectRow:zindex inComponent:0 animated:NO];
  54. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  55. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  56. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  57. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  58. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  59. //Localization
  60. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  61. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  62. }
  63. }
  64. return self;
  65. }
  66. - (void)didMoveToSuperview {
  67. }
  68. - (void)setTemperature:(NSString *)temperature {
  69. _temperature = temperature;
  70. // _temperaturePicker selectRow:zindex inComponent:0 animated:NO];
  71. if (_temperature) {
  72. NSInteger row = 50 + [temperature integerValue];
  73. [_temperaturePicker selectRow:row inComponent:0 animated:YES];
  74. }
  75. }
  76. #pragma mark - Main Logic
  77. - (NSString *)temperature {
  78. return [_temperatureArray objectAtIndex:[_temperaturePicker selectedRowInComponent:0]];
  79. }
  80. #pragma mark - Picker Delegate
  81. // 필수 사용메소드 2개 : 이 작업을 하면 피커에 데이터가 들어간다.
  82. // 피커를 사용하기 위해 반드시 사용되어야 할 필수 메소드이다.
  83. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
  84. return 1;
  85. }
  86. // 피커를 사용하기 위해 반드시 사용되어야 할 필수 메소드이다.
  87. - (NSInteger)pickerView:(UIPickerView *) pickerView numberOfRowsInComponent : (NSInteger)component{
  88. return _temperatureArray.count;
  89. }
  90. // 피커를 사용하기 위해 반드시 사용되어야 할 필수 델리게이트이다.
  91. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow: (NSInteger)row forComponent: (NSInteger)component{
  92. return _temperatureArray[row];
  93. }
  94. - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
  95. return 40.0f;
  96. }
  97. #pragma mark - UI Events
  98. - (IBAction)btnConfirmTouched:(id)sender {
  99. //validate
  100. [super btnConfirmTouched:sender];
  101. }
  102. @end