This is how I have implemented it for one button. You can use it for more buttons too.
-(IBAction)ButtonAction
{
if (Flag==0)
{
Flag=1;
[myButton setImage:[UIImage imageNamed:@"checkbox-filled.png"] forState:UIControlStateNormal];
}
else
{
[myButton setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
Flag=0;
}
}
Note : If you want only one button to get checked Just set all other buttons image as checkbox.png and the selected one's checkbox-filled.png.
EDIT
You can make a class for checkbox and then use it. Here is the code...
CheckButton.h
#import <Foundation/Foundation.h>
@interface CheckButton : UIButton {
BOOL _checked;
int chkButtonClickVal;
}
@property (nonatomic, setter=setChecked:) BOOL checked;
-(void) setChecked:(BOOL) check;
-(int)chkButtonClickVal;
@end
CheckButton.m
#import "CheckButton.h"
@implementation CheckButton
@synthesize checked = _checked;
-(id) init
{
if( self=[super init] )
{
chkButtonClickVal=0;
self.checked = NO;
[self addTarget:self action:@selector(OnCheck:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
-(void) awakeFromNib
{
self.checked = NO;
[self addTarget:self action:@selector(OnCheck:) forControlEvents:UIControlEventTouchUpInside];
}
-(void) dealloc
{
chkButtonClickVal=0;
[super dealloc];
}
-(void) setChecked:(BOOL) check
{
_checked = check;
if( _checked )
{
UIImage* img = [UIImage imageNamed:@"checkbox-checked.png"];
[self setImage:img forState:UIControlStateNormal];
chkButtonClickVal=1;
}
else
{
UIImage* img = [UIImage imageNamed:@"checkbox.png"];
[self setImage:img forState:UIControlStateNormal];
chkButtonClickVal=2;
}
//NSLog(@"%d",chkButtonClickVal);
}
-(int)chkButtonClickVal
{
return chkButtonClickVal;
}
-(void) OnCheck:(id) sender
{
self.checked = !_checked;
}
@end
I have done it in same way. Try you'll be able to achieve it.
Good Luck :)