Studie Studie - 1 year ago 99
iOS Question

How to change the color of an UIImage

I want not to change the backgroundColor of an UIImage,

but rather to change the color of the whole image.

Because I have got standard forms which I can move from popover to the view.

In my App it is possible to tinker the images to one big image, i.e a table.

Moreover I want change the color to white brown or what else.

But the problem is: I can only change the backgroundColor

Is there any way to change the color of the UIImage?

Thank you in advance

Answer Source
UIImage *image = [UIImage imageNamed:@"triangle.png"];

CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, image.CGImage);
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIImage *flippedImage = [UIImage imageWithCGImage:img.CGImage 
                                            scale:1.0 orientation: UIImageOrientationDownMirrored];

yourUIImageView.image = flippedImage;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download