-
-
Save kompozer/387210 to your computer and use it in GitHub Desktop.
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
@interface UIImage (Shadow) | |
+ (UIImage *)imageWithContentsOfFile:(NSString *)path withShadow:(BOOL)applyShadow; | |
+ (UIImage *)imageNamed:(NSString *)name withShadow:(BOOL)applyShadow; | |
+ (UIImage *)applyShadow:(UIImage *)theImage; | |
@end | |
@implementation UIImage (Shadow) | |
+ (UIImage *)imageWithContentsOfFile:(NSString *)path withShadow:(BOOL)applyShadow { | |
UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
if (!applyShadow) { | |
return image; | |
} | |
return [UIImage applyShadow:image]; | |
} | |
+ (UIImage *)imageNamed:(NSString *)name withShadow:(BOOL)applyShadow | |
{ | |
UIImage *image = [UIImage imageNamed:name]; | |
if (!image) { | |
return image; | |
} | |
if (!applyShadow) { | |
return image; | |
} | |
return [UIImage applyShadow:image]; | |
} | |
+ (UIImage *)applyShadow:(UIImage *)theImage | |
{ | |
UIGraphicsBeginImageContext(CGSizeMake(theImage.size.width + 12, theImage.size.height + 12)); | |
CGContextSetShadow(UIGraphicsGetCurrentContext(), CGSizeMake(6.0f, -6.0f), 6.0f); | |
[theImage drawAtPoint:CGPointZero]; | |
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return result; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adds a shadow to an UIImage