Skip to content

Instantly share code, notes, and snippets.

@tempire
Last active May 11, 2016 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tempire/0cee2559bc5c0830fe289f9460e171b3 to your computer and use it in GitHub Desktop.
Save tempire/0cee2559bc5c0830fe289f9460e171b3 to your computer and use it in GitHub Desktop.
objc block closure
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated duration:(NSTimeInterval)duration completion:(void(^)(BOOL finished))completion {
void (^highlight)(UIView *, BOOL) = ^void(UIView *view, BOOL highlight) {
if (highlight) {
view.layer.borderWidth = 0.0;
view.layer.borderColor = [UIColor clearColor].CGColor;
view.layer.shadowOpacity = 0.0;
}
else {
view.layer.borderWidth = 1.0;
view.layer.borderColor = [UIColor blackColor].CGColor;
view.layer.shadowOpacity = 2.0;
view.layer.shadowColor = [UIColor yellowColor].CGColor;
view.layer.shadowOffset = CGSizeMake(0, 0);
view.layer.shadowRadius = 5.0;
}
};
if (animated) {
[UIView animateWithDuration:duration animations:^{
highlight(self, highlighted);
} completion:completion];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment