UIImage+ERCategory.m 665 B

12345678910111213141516171819202122232425
  1. //
  2. // UIImage+ERCategory.m
  3. // ErHuDemo
  4. //
  5. // Created by 胡广宇 on 2017/7/11.
  6. // Copyright © 2017年 胡广宇. All rights reserved.
  7. //
  8. #import "UIImage+ERCategory.h"
  9. @implementation UIImage (ERCategory)
  10. + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
  11. {
  12. CGRect rect=CGRectMake(0, 0, size.width, size.height);
  13. UIGraphicsBeginImageContext(rect.size);
  14. CGContextRef context = UIGraphicsGetCurrentContext();
  15. CGContextSetFillColorWithColor(context, [color CGColor]);
  16. CGContextFillRect(context, rect);
  17. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  18. UIGraphicsEndImageContext();
  19. return image;
  20. }
  21. @end