I have a set of graphics that I would like to reuse within my apps. They are buttons and images with transparency. Rather than having dozens of hard-coded button images, I would love to have a single button image, and be able to assign a color to it dynamically, like the navigation bar and it's tint color.
Is it possible to replace/shift the hue of a UIView?
Alternatively: I know that if I overlay a transparent image over another UIView, then I can change the background color and the two images will blend together. But the transparent regions will take on the hue of the background.
Is there a way to keep transparent regions transparent, while blending the two images together? I heard there are clipping masks, but have never worked with them.
Thank you!
Update:
This should work, but returns nil image, I've seen someone else report the same issue. Maybe this will work in the future
-(void)doHueAdjustFilter
{
//does not work, returns nil image
CIImage* inputImage = [CIImage imageWithCGImage:[[UIImage imageNamed:@"button.jpg"]CGImage]];
CIFilter *myFilter;
NSDictionary *myFilterAttributes;
myFilter = [CIFilter filterWithName:@"CIHueAdjust"];
[myFilter setDefaults];
myFilterAttributes = [myFilter attributes];
[myFilterAttributes setValue:inputImage forKey:@"inputImage"];
[myFilterAttributes setValue:[NSNumber numberWithFloat:0.9] forKey:@"inputAngle"];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *ciimage = [myFilter outputImage];
CGImageRef cgimg = [context createCGImage:ciimage fromRect:[ciimage extent]];
UIImage *uimage = [UIImage imageWithCGImage:cgimg scale:1.0f orientation:UIImageOrientationUp];
[caduceusImageView setImage:uimage];
CGImageRelease(cgimg);
}