0

I was trying to use the method outlined here for changing the color of a UIImage used for a UIView. I was hoping this method would ignore whitespace but it does not.

Here is the original image in which I'd like to replace the red with blue.

enter image description here

Here is the code

UIImage *image = [UIImage imageNamed:@"star-badge"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:...];
imageView.tintColor = [UIColor blueColor];
imageView.image = image;
[self.view addSubview:imageView];

but this is the result

enter image description here

is there a way to ignore the white space or only change the red color?

Community
  • 1
  • 1
Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
  • 1
    Change the original image so that the middle is transparent instead of white, then the method you're using should work. If need be, display it on a white background. – David Berry Feb 05 '15 at 21:52

2 Answers2

3

Change the original image so that the middle is transparent instead of white, then the method you're using should work. If need be, display it on a white background.

David Berry
  • 40,941
  • 12
  • 84
  • 95
  • Thanks, will try. Out of curiosity, what if the star had to be black or some color other than white? You'd have to add a background in that case? – Kevin_TA Feb 05 '15 at 22:29
  • Yeah, the easiest way to handle it would be with a smaller background (so it doesn't show behind the rounded colors) in whatever color you want the star to be. – David Berry Feb 05 '15 at 22:34
  • Alternatively, there's some ideas [here](http://stackoverflow.com/questions/1698971/uiimage-color-changing) for changing specific colors in an image. You could also probably do something with the newer `CoreImage` – David Berry Feb 05 '15 at 22:36
  • [Here](https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_filer_recipes/ci_filter_recipes.html#//apple_ref/doc/uid/TP30001185-CH4-SW1) in the `CoreImage` documentation it talks about color keying, which is basically what you want to do. – David Berry Feb 05 '15 at 22:39
0

As David says, you need a transparent star, attached the image how should be just in case you cant handle it on photoshop

Modified Image

dminones
  • 2,236
  • 20
  • 21