Guest User

Untitled

a guest
Jan 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. - (void)highlightButton:(UIButton*)button withDuration:(CGFloat)duration {
  2. UIImage* image = [button imageForState:UIControlStateNormal];
  3.  
  4. UIGraphicsBeginImageContext(image.size);
  5. CGContextRef context = UIGraphicsGetCurrentContext();
  6. UIGraphicsPushContext(context);
  7.  
  8. [image drawAtPoint:CGPointZero];
  9. [[UIColor colorWithWhite:1.0 alpha:1.0] set];
  10. UIRectFillUsingBlendMode(CGRectMake(0, 0, image.size.width, image.size.height), kCGBlendModeSourceIn);
  11.  
  12. UIGraphicsPopContext();
  13.  
  14. UIImage* mask = UIGraphicsGetImageFromCurrentImageContext();
  15.  
  16. UIGraphicsEndImageContext();
  17.  
  18. //Add the mask on top of the source button
  19. UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
  20. button.frame.size.width, button.frame.size.height)];
  21. imageView.image = mask;
  22. imageView.alpha = 0.0;
  23. [button addSubview:imageView];
  24.  
  25. CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
  26. anim.fromValue = [NSNumber numberWithFloat:0.0];
  27. anim.toValue = [NSNumber numberWithFloat:0.5];
  28. anim.repeatCount = 2;
  29. anim.autoreverses = YES;
  30. anim.duration = duration/(anim.repeatCount*2);
  31. [imageView.layer addAnimation:anim forKey:@"opacity"];
  32.  
  33. [imageView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:(anim.repeatCount*anim.duration*2)+.2];
  34. [imageView release];
  35. }
Add Comment
Please, Sign In to add comment