Created
August 8, 2017 08:01
-
-
Save AlexZverusha/ec5950931d1e245f1f3d28597ee2a169 to your computer and use it in GitHub Desktop.
CheckBox by Vladimir Kalinichenko
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 "MBButton.h" | |
@interface MBCheckBox : MBButton | |
@property (nonatomic) BOOL isActive; | |
- (void)setActivated:(BOOL)activated animated:(BOOL)animated; | |
@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 "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