Created
January 6, 2012 18:48
-
-
Save jamztang/1571875 to your computer and use it in GitHub Desktop.
Creating a placeholder UIImage dynamically with color
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
| // | |
| // UIImage+JTColor.h | |
| // | |
| // Created by james on 8/22/11. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface UIImage (JTColor) | |
| + (UIImage *)imageWithColor:(UIColor *)color; | |
| @end |
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
| // | |
| // UIImage+JTColor.m | |
| // | |
| // Created by james on 8/22/11. | |
| // | |
| #import "UIImage+JTColor.h" | |
| @implementation UIImage (JTColor) | |
| + (UIImage *)imageWithColor:(UIColor *)color { | |
| CGRect rect = CGRectMake(0, 0, 1, 1); | |
| // Create a 1 by 1 pixel context | |
| UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); | |
| [color setFill]; | |
| UIRectFill(rect); // Fill it with your color | |
| UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); | |
| return image; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loving it, hope it stays here so I can use it in my podfiles!