forked from ahmetardal/SSCheckBoxView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSCheckBoxViewViewController.m
More file actions
93 lines (75 loc) · 2.29 KB
/
SSCheckBoxViewViewController.m
File metadata and controls
93 lines (75 loc) · 2.29 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
//
// SSCheckBoxViewViewController.m
// SSCheckBoxView
//
// Created by Ahmet Ardal on 12/6/11.
// Copyright 2011 SpinningSphere Labs. All rights reserved.
//
#import "SSCheckBoxViewViewController.h"
#import "SSCheckBoxView.h"
#import "UIHelpers.h"
@implementation SSCheckBoxViewViewController
@synthesize checkboxes;
- (void) dealloc
{
[self.checkboxes release];
[super dealloc];
}
- (void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark View lifecycle
- (void) checkBoxViewChangedState:(SSCheckBoxView *)cbv
{
NSLog(@"checkBoxViewChangedState: %d", cbv.checked);
[UIHelpers showAlertWithTitle:@"CheckBox State Changed"
msg:[NSString stringWithFormat:@"checkBoxView state: %d", cbv.checked]];
// toggle all
for (SSCheckBoxView *cbv in self.checkboxes) {
cbv.enabled = !cbv.enabled;
}
}
- (void) viewDidLoad
{
[super viewDidLoad];
NSMutableArray *a = [[NSMutableArray alloc] initWithCapacity:10];
self.checkboxes = a;
[a release];
SSCheckBoxView *cbv = nil;
CGRect frame = CGRectMake(20, 20, 240, 30);
for (int i = 0; i < 10; ++i) {
SSCheckBoxViewStyle style = (i % kSSCheckBoxViewStylesCount);
BOOL checked = (i < 5);
cbv = [[SSCheckBoxView alloc] initWithFrame:frame
style:style
checked:checked];
[cbv setText:[NSString stringWithFormat:@"Option #%02d", (i + 1)]];
[self.view addSubview:cbv];
[self.checkboxes addObject:cbv];
[cbv release];
frame.origin.y += 36;
}
frame.origin.y += 24;
cbv = [[SSCheckBoxView alloc] initWithFrame:frame
style:kSSCheckBoxViewStyleGlossy
checked:YES];
[cbv setText:@"Enable All"];
[cbv setStateChangedTarget:self
selector:@selector(checkBoxViewChangedState:)];
// handle state changed event using blocks
/*
__block typeof(self) me = self;
[cbv setStateChangedBlock:^(SSCheckBoxView *v) {
[me checkBoxViewChangedState:v];
}];
*/
[self.view addSubview:cbv];
[cbv release];
}
- (void) viewDidUnload
{
[super viewDidUnload];
}
@end