UIImage+PYJColorBecomeImage.h:

//
//  UIImage+PYJColorBecomeImage.h
//  颜色转成图片
//
//  Created by PengYunjing on 16/8/24.
//  Copyright © 2016年 PYJ. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImage (PYJColorBecomeImage)

+ (UIImage*)imageWithColor:(UIColor*)color;

@end

 

UIImage+PYJColorBecomeImage.m:

//
//  UIImage+PYJColorBecomeImage.m
//  颜色转成图片
//
//  Created by PengYunjing on 16/8/24.
//  Copyright © 2016年 PYJ. All rights reserved.
//

#import "UIImage+PYJColorBecomeImage.h"

@implementation UIImage (PYJColorBecomeImage)

+ (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 *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

@end

 

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-07
  • 2021-10-23
  • 2021-06-08
  • 2021-11-12
  • 2021-11-22
  • 2021-06-23
相关资源
相似解决方案