| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- //
- // UICheckBox.m
- // JasonDevelop
- //
- // Created by Hslee on 10. 11. 22..
- // Copyright 2013 AnchorData. All rights reserved.
- //
- @import ObjectiveC.runtime;
- #import "CustomCheckBox.h"
- #import "CustomLabel.h"
- @interface CustomCheckBox () {
- UIImage *_imgNormal, *_imgHighlighted, *_imgDisbale;
- UIColor *_textColorNormal, *_textColorHighlight;
- }
- @end
- @implementation CustomCheckBox
- @synthesize checked = _checked;
- - (id)initWithFrame:(CGRect)frame {//소스레벨에서 로드하는 경우, 초기화
- if (self = [super initWithFrame:frame]) {
- // Initialization code
- _imgNormal = [UIImage imageNamed:@"common_checkbox_default"];
- _imgHighlighted = [UIImage imageNamed:@"common_checkbox_checked"];
- _imgDisbale = [UIImage imageNamed:@"common_checkbox_disable"];
- self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [self setImage:_imgNormal forState:UIControlStateNormal];
- [self addTarget:self action:@selector(checkBoxClicked) forControlEvents:UIControlEventTouchUpInside];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame normalImage:(UIImage *)normalImage highlightImage:(UIImage *)highlightImage {//소스레벨에서 로드하는 경우, 초기화
- if (self = [super initWithFrame:frame]) {
- _imgNormal = normalImage;
- _imgHighlighted = highlightImage;
- self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [self setImage:_imgNormal forState:UIControlStateNormal];
- [self addTarget:self action:@selector(checkBoxClicked) forControlEvents:UIControlEventTouchUpInside];
- }
- return self;
- }
- - (void)awakeFromNib {//NIB에서 로드하는 경우, 초기화
- self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _imgNormal = [UIImage imageNamed:@"common_checkbox_default"];
- _imgHighlighted = [UIImage imageNamed:@"common_checkbox_checked"];
- _imgDisbale = [UIImage imageNamed:@"common_checkbox_disable"];
- _textColorNormal = [self titleColorForState:UIControlStateNormal];
- _textColorHighlight = [self titleColorForState:UIControlStateHighlighted];
- [self setImage:_imgNormal forState:UIControlStateNormal];
- [self addTarget:self action:@selector(checkBoxClicked) forControlEvents:UIControlEventTouchUpInside];
- }
- - (void)setDaySelectBgImage:(NSInteger)type{
-
- if (type == 1) {
- _imgNormal = [UIImage imageNamed:@"common_checkbox_cal_first"];
- _imgHighlighted = [UIImage imageNamed:@"common_checkbox_cal_first_checked"];
- }
- else if (type == 2) {
- _imgNormal = [UIImage imageNamed:@"common_checkbox_cal"];
- _imgHighlighted = [UIImage imageNamed:@"common_checkbox_cal_checked"];
- }
- else if (type == 3) {
- _imgNormal = [UIImage imageNamed:@"common_checkbox_cal_last"];
- _imgHighlighted = [UIImage imageNamed:@"common_checkbox_cal_last_checked"];
- }
- else if (type == 4) {
-
- _imgNormal = [UIImage imageNamed:@"common_radiobox_default"];
- _imgHighlighted = [UIImage imageNamed:@"common_radiobox_checked"];
- }
-
-
- [self setImage:_imgNormal forState:UIControlStateNormal];
- [self addTarget:self action:@selector(checkBoxClicked) forControlEvents:UIControlEventTouchUpInside];
- }
- - (IBAction)checkBoxClicked {
- if (self.checked == NO) {
- self.checked = YES;
- } else {
- self.checked = NO;
- }
- if ([self.delegate respondsToSelector:@selector(didCheckBoxClicked:)]) {
- [self.delegate didCheckBoxClicked:self];
- }
- }
- - (BOOL)isChecked {
- return _checked;
- }
- - (BOOL)checked {
- return _disable ? NO : _checked;
- }
- //체크 On/Off
- - (void)setChecked:(BOOL)checked {
- _checked = checked;
- if (_checked) {
- [self setImage:_imgHighlighted forState:UIControlStateNormal];
- [self setTitleColor:_textColorHighlight forState:UIControlStateNormal];
- } else {
- [self setImage:_imgNormal forState:UIControlStateNormal];
- [self setTitleColor:_textColorNormal forState:UIControlStateNormal];
- }
- if (_value) {
- objc_setAssociatedObject(_value, ksCustomCheckBoxStatus, [NSNumber numberWithBool:_checked], OBJC_ASSOCIATION_COPY_NONATOMIC);
- }
- }
- - (BOOL)getCheckStatusFromValue {
- BOOL isChecked = NO;
- if (_value) {
- isChecked = [objc_getAssociatedObject(_value, ksCustomCheckBoxStatus) boolValue];
- }
- return isChecked;
- }
- //disable On/Off
- - (void)setDisable:(BOOL)disable {
- _disable = _checked = disable;
- if (_disable && _imgDisbale) {
- [self setImage:_imgDisbale forState:UIControlStateNormal];
- } else {
- [self setCheckedDisable:_checkedDisable];
- }
- }
- //체크된 상태에서 On/Off
- - (void)setCheckedDisable:(BOOL)checkedDisable {
- _checkedDisable = _checked = checkedDisable;
- if (_checkedDisable) {
- [self setImage:_imgDisbale forState:UIControlStateNormal];
- } else {
- [self setImage:_imgNormal forState:UIControlStateNormal];
- }
- }
- @end
|