-1

I want to set image in UIButton. It has orange color. Then I insert it like this:

[cell.playButton setImage:[UIImage imageNamed:@"Oval 135 Copy + Triangle 1 Copy.png"] forState:UIControlStateNormal];

When I launch my app this image changes its color, how it is possible and how this problem may be solved? I add simulator picture and photo:

enter image description here

Yuri Chukhlib
  • 120
  • 11

1 Answers1

1

Did you create your button using [UIButton buttonWithType:UIButtonTypeCustom] ? If so, the button will automatically try to tint your image with the tintColor value of the button.

If you want to opt out of this behavior, you can do it like so :

UIImage *image = [UIImage imageNamed:@"Oval 135 Copy + Triangle 1 Copy.png"];
UIImage *originalImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[cell.playButton setImage:originalImage forState:UIControlStateNormal];

Alternatively you can also create your button using [UIButton buttonWithType:UIButtonTypeCustom], but its behavior will be slightly different, so choose the option that works best for you.

deadbeef
  • 5,409
  • 2
  • 17
  • 47