Forked from troystribling/UIImage+Extensions.h
Last active
December 16, 2015 18:39
-
-
Save rowanj/5479492 to your computer and use it in GitHub Desktop.
Make a blank UI image with a given size, and optional fill color
This file contains 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
#import <Foundation/Foundation.h> | |
@interface UIImage (Extensions) | |
+ (UIImage*)blankImage:(CGSize)_size; | |
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color; | |
@end |
This file contains 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
#import "UIImage+Extensions.h" | |
@implementation UIImage (Extensions) | |
+ (UIImage*)blankImage:(CGSize)_size { | |
return [self blankImage:_size withColor:nil]; | |
} | |
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color { | |
if (!_color) { | |
_color = [UIColor clearColor]; | |
} | |
UIGraphicsBeginImageContext(_size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetFillColorWithColor(context, _color.CGColor); | |
CGContextFillRect(context, CGRectMake(0.0, 0.0, _size.width, _size.height)); | |
UIImage* outputImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return outputImage; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment