Reputation: 1588
I don't know whether it sounds silly,
I have an image which will be added in the UIImageView
or an UIButton
. That image contains some texts in the Red color and the background is black. Is it possible to change the BG color as well as the Text color to custom color. Is that possible ??
Upvotes: 1
Views: 1789
Reputation: 2508
If, after considering George's answer, you still need to modify the colours, you could try using Core Image filters.
The following example adjusts the hue of a UIImageView
called screenImage
by an angle given in angle
.
- (void)rebuildFilterChain:(double)angle {
UIImage *uiImage = [UIImage imageNamed:@"background.jpg"];
CIImage *image = [CIImage imageWithCGImage:[uiImage CGImage]];
CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
[hueAdjust setDefaults];
[hueAdjust setValue:image forKey: @"inputImage"];
[hueAdjust setValue: [NSNumber numberWithFloat:angle] forKey: @"inputAngle"];
self.resultImage = [hueAdjust valueForKey: @"outputImage"];
CGImageRef cgImage = [context createCGImage:resultImage fromRect:resultImage.extent];
screenImage.image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
}
The full list of Core Image filters is on the Apple site.
Upvotes: 3
Reputation: 4029
Why do you use an image? If you have a background color that means you are using a flat color...not an image actually. So you can set the background color of the button as well as the title color. If you are doing this just to have rounded corners , don't.
Just import <QuartzCore/QuartzCore.h>
and do this:
button.layer.cornerRadius = 8;
button.layer.masksToBounds = TRUE;
Hope this helps.
Cheers!
Upvotes: 1