Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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
Add Comment
Please, Sign In to add comment