color 转 image

来源:互联网 发布:win7变色龙引导mac 编辑:程序博客网 时间:2024/06/05 03:01

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

{

    CGRect rect=CGRectMake(0,0,1,1);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);

    CGContextFillRect(context, rect);

    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return theImage;

}

    self.view.backgroundColor = [UIColor colorWithRed:242/255.0green:242/255.0blue:242/255.0alpha:1.0f];

    UIImage * image1 = [[UIImagealloc]init];

    UIImage * image2 = [[UIImagealloc]init];

    image1 = [selfcreateImageWithColor:[UIColorcolorWithRed:246/255.0green:246/255.0blue:246/255.0alpha:1.0f]];

    image2 = [selfcreateImageWithColor:[UIColorwhiteColor]];



0 0
原创粉丝点击