Skip to content

Instantly share code, notes, and snippets.

@AlexZverusha
Created August 8, 2017 08:01
Show Gist options
  • Save AlexZverusha/ec5950931d1e245f1f3d28597ee2a169 to your computer and use it in GitHub Desktop.
Save AlexZverusha/ec5950931d1e245f1f3d28597ee2a169 to your computer and use it in GitHub Desktop.
CheckBox by Vladimir Kalinichenko
#import "MBButton.h"
@interface MBCheckBox : MBButton
@property (nonatomic) BOOL isActive;
- (void)setActivated:(BOOL)activated animated:(BOOL)animated;
@end
#import "MBCheckBox.h"
static NSString *checkBoxOn = @"loginCheckBoxOn";
static NSString *checkBoxOff = @"loginCheckBox";
@interface MBCheckBox()
@end
@implementation MBCheckBox
- (void)touchEnded{
[super touchEnded];
if(self.isActive){
[self setActivated:NO animated:YES];
}else{
[self setActivated:YES animated:YES];
}
}
- (void)setActivated:(BOOL)activated animated:(BOOL)animated{
self.isActive = activated;
UIImage *imageForState;
if(self.isActive){
imageForState = [UIImage imageNamed:checkBoxOn];
}else{
imageForState = [UIImage imageNamed:checkBoxOff];
}
CGRect boundsOld = self.picture.bounds;
CGRect bounds = boundsOld;
bounds.size.height /= 1.5;
bounds.size.width /= 1.5;
[UIView animateWithDuration:0.1 animations:^{
self.picture.bounds = bounds;
} completion:^(BOOL finished) {
dispatch_async(dispatch_get_main_queue(), ^{
self.picture.image = imageForState;
});
[UIView animateWithDuration:0.05 animations:^{
self.picture.bounds = boundsOld;
}];
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment