UIColor生成UIImage

来源:互联网 发布:java 加载 scala脚本 编辑:程序博客网 时间:2024/05/19 03:42
  1. - (UIImage *) createImageWithColor: (UIColor *) color
  2. {
  3.     CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
  4.     UIGraphicsBeginImageContext(rect.size);
  5.     CGContextRef context = UIGraphicsGetCurrentContext();
  6.     CGContextSetFillColorWithColor(context, [color CGColor]);
  7.     CGContextFillRect(context, rect);
  8.     
  9.     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
  10.     UIGraphicsEndImageContext();
  11.     return theImage;
  12. }
原创粉丝点击