您的位置:首页 > 移动开发 > IOS开发

iOS 颜色填充

2016-06-02 15:19 369 查看
+ (UIImage
*)jj_imageWithColor:(UIColor
*)color {
   
return
[self jj_imageWithColor:color
height:1.0f];

}

+ (UIImage
*)jj_imageWithColor:(UIColor
*)color height:(CGFloat)height {
   
CGRect rect =
CGRectMake(0.0f,
0.0f,
1.0f, height);
//1.开启图形上下文
   
UIGraphicsBeginImageContext(rect.size);
//2.获取当前的图形上下文
   
CGContextRef
context =
UIGraphicsGetCurrentContext();
//3.设置颜色填充
   
CGContextSetFillColorWithColor(context, [color
CGColor]);
//4.填充模式
   
CGContextFillRect(context, rect);
//5.获取到当前的图形上下文 (UIImage)
   
UIImage
*image =
UIGraphicsGetImageFromCurrentImageContext();
//6.关闭图形上下文
   
UIGraphicsEndImageContext();

   

   
return image;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios uiimage