Created
August 24, 2011 12:10
-
-
Save aliirz/1167926 to your computer and use it in GitHub Desktop.
A Checkbox Control for iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface UICheckBox : UIButton { | |
BOOL checked; | |
} | |
@property (nonatomic, assign) BOOL checked; | |
-(IBAction)checkBoxClicked; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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