Skip to content

Instantly share code, notes, and snippets.

@troystribling
Created May 28, 2012 00:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save troystribling/2816511 to your computer and use it in GitHub Desktop.
Save troystribling/2816511 to your computer and use it in GitHub Desktop.
Blank UIImage with Specified Color
#import <Foundation/Foundation.h>
@interface UIImage (Extensions)
+ (UIImage*)blankImage:(CGSize)_size;
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color;
@end
#import "UIImage+Extensions.h"
@implementation UIImage (Extensions)
+ (UIImage*)blankImage:(CGSize)_size {
return [self blankImage:_size withColor:[UIColor whiteColor]];
}
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color {
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
#import <Foundation/Foundation.h>
@interface UIImage (Extensions)
+ (UIImage*)blankImage:(CGSize)_size;
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color;
@end
#import "UIImage+Extensions.h"
@implementation UIImage (Extensions)
+ (UIImage*)blankImage:(CGSize)_size {
return [self blankImage:_size withColor:[UIColor whiteColor]];
}
+ (UIImage*)blankImage:(CGSize)_size withColor:(UIColor*)_color {
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