UIImage+Image.m
809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// UIImage+Image.m
// XianYu
//
// Created by li bo on 16/5/28.
// Copyright © 2016年 li bo. All rights reserved.
//
#import "UIImage+Image.h"
@implementation UIImage (Image)
+ (UIImage *)imageWithColor:(UIColor *)color {
//描述一个矩形
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
//开启图形上下文
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
//获得图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//使用color演示填充上下文
CGContextSetFillColorWithColor(ctx, [color CGColor]);
//渲染上下文
CGContextFillRect(ctx, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//关闭图形上下文
UIGraphicsEndImageContext();
return image;
}
@end