-
Notifications
You must be signed in to change notification settings - Fork 23
/
UICheckbox.m
executable file
·81 lines (63 loc) · 1.85 KB
/
UICheckbox.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// UICheckbox.m
//
// Author: Brayden Wilmoth
// Co-Author: Jordan Perry
// Edited: 07/17/2012
//
// Copyright (c) 2012 Brayden Wilmoth. All rights reserved.
// http://www.github.com/brayden/
// http://www.github.com/jordanperry/
//
#import "UICheckbox.h"
@interface UICheckbox (){
BOOL loaded;
}
@property(nonatomic, strong)UILabel *textLabel;
@end
@implementation UICheckbox
@synthesize checked = _checked;
@synthesize disabled = _disabled;
@synthesize text = _text;
@synthesize textLabel = _textLabel;
-(void)awakeFromNib {
self.backgroundColor = [UIColor clearColor];
}
-(void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"uicheckbox_%@checked.png", (self.checked) ? @"" : @"un"]];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
if(self.disabled) {
self.userInteractionEnabled = FALSE;
self.alpha = 0.7f;
} else {
self.userInteractionEnabled = TRUE;
self.alpha = 1.0f;
}
if(self.text) {
if(!loaded) {
_textLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width + 5, 0, 1024, 15)];
_textLabel.backgroundColor = [UIColor clearColor];
_textLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:_textLabel];
loaded = TRUE;
}
_textLabel.text = self.text;
}
}
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
[self setChecked:!self.checked];
return TRUE;
}
-(void)setChecked:(BOOL)boolValue {
_checked = boolValue;
[self setNeedsDisplay];
}
-(void)setDisabled:(BOOL)boolValue {
_disabled = boolValue;
[self setNeedsDisplay];
}
-(void)setText:(NSString *)stringValue {
_text = stringValue;
[self setNeedsDisplay];
}
@end