CheckBox Button
#import <Foundation/Foundation.h>
@interface CheckButton : UIButton {
BOOL _checked;
}
@property (nonatomic, setter=setChecked) BOOL checked;
-(void) setChecked:(BOOL) check;
@end
#import "CheckButton.h"
@implementation CheckButton
@synthesize checked = _checked;
-(id) init
{
if( self=[super init] )
{
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
{
[super dealloc];
}
-(void) setChecked:(BOOL) check
{
_checked = check;
if( _checked )
{
UIImage* img = [UIImage imageNamed:@"check.png"];
[self setImage:img forState:UIControlStateNormal];
}
else
{
UIImage* img = [UIImage imageNamed:@"uncheck.png"];
[self setImage:img forState:UIControlStateNormal];
}
}
-(void) OnCheck:(id) sender
{
self.checked = !_checked;
}
@end