1

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 ??

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Perseus
  • 1,546
  • 4
  • 30
  • 55
  • Are you looking for the one as in [this link][1] ? [1]: http://stackoverflow.com/questions/1117211/how-would-i-tint-an-image-programatically-on-the-iphone – Ananth Jul 09 '12 at 07:08
  • It is like a tint. It doesn't actually change the color right ? – Perseus Jul 09 '12 at 07:24

2 Answers2

3

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.

Martin Kenny
  • 2,468
  • 1
  • 19
  • 16
1

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!

George
  • 4,029
  • 1
  • 23
  • 31
  • Thank you. Actually, I am having an image which consists of the text (like glittering) of height 50. And I don't know which font they are using. Looks stlyish. That text color is Red. I am thinking , whether it is possible to change that particular text color in that image. That is places in a UIImageView. – Perseus Jul 09 '12 at 07:24