iOS UIimage和UI color转换

来源:互联网 发布:mac系统打不开exe文件 编辑:程序博客网 时间:2024/06/05 17:04

由color转换到image

- (UIImage*)createImageWithColor: (UIColor*) color

{

   CGRect rect=CGRectMake(0.0f,0.0f, 1.0f,1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [colorCGColor]);

   CGContextFillRect(context, rect);

    UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

   return theImage;

}

由image转换成color

 [UIColorcolorWithPatternImage:[UIImageimageNamed:@"imgName"]];


0 0
原创粉丝点击