Skip to content

Instantly share code, notes, and snippets.

@shiweifu
Last active January 2, 2016 13:59
Show Gist options
  • Save shiweifu/8314215 to your computer and use it in GitHub Desktop.
Save shiweifu/8314215 to your computer and use it in GitHub Desktop.
//
// Created by shiweifu on 14-1-8.
// Copyright (c) 2014 weifu. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface UIImage (imageWithColor)
+ (UIImage *)imageWithColor:(UIColor *)color;
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size;
@end
//
// Created by shiweifu on 14-1-8.
// Copyright (c) 2014 weifu. All rights reserved.
//
#import "UIImage+imageWithColor.h"
@implementation UIImage (imageWithColor)
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
Pod::Spec.new do |s|
s.name = "UIImage-imageWithColor"
s.version = "0.1"
s.summary = "test gist"
s.homepage = "https://gist.github.com/shiweifu/8314215"
s.author = { "weifu shi" => "[email protected]" }
s.platform = :ios
#s.source = { :git => "git://gist.github.com/6009092.git", :tag => '0.1' }
s.source = { :git => "git://gist.github.com/8314215.git"}
s.requires_arc = true
s.ios.deployment_target = '5.0'
s.source_files = '*.{h,m}'
s.license = { :type => 'MIT', :file => 'LICENSE' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment