Skip to content

Instantly share code, notes, and snippets.

@aliirz
Created August 24, 2011 12:10
Show Gist options
  • Save aliirz/1167926 to your computer and use it in GitHub Desktop.
Save aliirz/1167926 to your computer and use it in GitHub Desktop.
A Checkbox Control for iOS
#import <Foundation/Foundation.h>
@interface UICheckBox : UIButton {
BOOL checked;
}
@property (nonatomic, assign) BOOL checked;
-(IBAction)checkBoxClicked;
@end
#import "UICheckBox.h"
@implementation UICheckBox
@synthesize checked;
-(id)initWithFrame:(CGRect)frame{
if(self == [super initWithFrame:frame]){
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self setImage:[UIImage imageNamed:@"checkbox_not_ticked.png"] forState:UIControlStateNormal];
[self addTarget:self action:@selector(checkBoxClicked) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
-(IBAction)checkBoxClicked{
if(self.checked == NO)
{
self.checked = YES;
[self setImage:[UIImage imageNamed:@"checkbox_ticked.png"] forState:UIControlStateNormal];
}
else{
self.checked = NO;
[self setImage:[UIImage imageNamed:@"checkbox_not_ticked.png"] forState:UIControlStateNormal];
}
}
-(void) dealloc{
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment