Guest User

Untitled

a guest
May 24th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. @interface UIImage (Shadow)
  2.  
  3. + (UIImage *)imageWithContentsOfFile:(NSString *)path withShadow:(BOOL)applyShadow;
  4.  
  5. + (UIImage *)imageNamed:(NSString *)name withShadow:(BOOL)applyShadow;
  6.  
  7. + (UIImage *)applyShadow:(UIImage *)theImage;
  8.  
  9. @end
  10.  
  11. @implementation UIImage (Shadow)
  12.  
  13. + (UIImage *)imageWithContentsOfFile:(NSString *)path withShadow:(BOOL)applyShadow {
  14. UIImage *image = [UIImage imageWithContentsOfFile:path];
  15. if (!applyShadow) {
  16. return image;
  17. }
  18.  
  19. return [UIImage applyShadow:image];
  20. }
  21.  
  22. + (UIImage *)imageNamed:(NSString *)name withShadow:(BOOL)applyShadow
  23. {
  24. UIImage *image = [UIImage imageNamed:name];
  25. if (!image) {
  26. return image;
  27. }
  28. if (!applyShadow) {
  29. return image;
  30. }
  31.  
  32. return [UIImage applyShadow:image];
  33. }
  34.  
  35. + (UIImage *)applyShadow:(UIImage *)theImage
  36. {
  37. UIGraphicsBeginImageContext(CGSizeMake(theImage.size.width + 12, theImage.size.height + 12));
  38. CGContextSetShadow(UIGraphicsGetCurrentContext(), CGSizeMake(6.0f, -6.0f), 6.0f);
  39. [theImage drawAtPoint:CGPointZero];
  40. UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
  41. UIGraphicsEndImageContext();
  42.  
  43. return result;
  44. }
  45.  
  46. @end
Add Comment
Please, Sign In to add comment