Skip to content

Instantly share code, notes, and snippets.

@adamweeks
Created July 27, 2013 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamweeks/6095919 to your computer and use it in GitHub Desktop.
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
//
// 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
//
// 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