Created
May 28, 2012 00:18
-
-
Save troystribling/2816511 to your computer and use it in GitHub Desktop.
Blank UIImage with Specified 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:[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 |
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:[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