Add buttons on view of controller
for (int i = 0; i < 3; i++) {
UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
[but setImage:[UIImage imageNamed:@"checkbox.png"]
forState:UIControlStateNormal];
[but setImage:[UIImage imageNamed:@"checkedbox.png"]
forState:UIControlStateSelected];
[but setFrame:CGRectMake(0, 0, 25, 25)];
[but setCenter:CGPointMake(410, 385+i*40)];
if (i == 0) {
[but setSelected:YES];
}
[but setTag:i];
[but addTarget:self action:@selector(checkboxButton:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:but];
}
Action for buttons:
- (void)checkboxButton:(UIButton *)button
{
for (UIButton *but in [self subviews]) {
// This is the view that
button are in
if ([but isKindOfClass:[UIButton class]] && ![but isEqual:button]) {
[but setSelected:NO];
}
}
if (!button.selected) {
button.selected = !button.selected;
}
}