Created
July 27, 2013 19:03
-
-
Save adamweeks/6095919 to your computer and use it in GitHub Desktop.
This is a simple UIImage category for creating an image based on a UIColor
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
// | |
// UIImage+UIColor.h | |
// | |
// Created by Adam Weeks on 7/27/13. | |
// Copyright (c) 2013 AppsVersusRobots, LLC. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIImage (UIColor) | |
+(UIImage *)imageWithUIColor:(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
// | |
// UIImage+UIColor.m | |
// | |
// Created by Adam Weeks on 7/27/13. | |
// Copyright (c) 2013 AppsVersusRobots, LLC. All rights reserved. | |
// | |
#import "UIImage+UIColor.h" | |
@implementation UIImage (UIColor) | |
+(UIImage *)imageWithUIColor:(UIColor *)color | |
{ | |
CGRect rect = CGRectMake(0, 0, 1, 1); | |
UIGraphicsBeginImageContext(rect.size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetFillColorWithColor(context, | |
[color CGColor]); | |
CGContextFillRect(context, rect); | |
UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return img; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment