0

I created a button in storyboard and I now want to change its tint in code. Changing the tint alone has no effect as I think I need to set the UIImageRenderingMode. However, my code is not working:

Can anyone suggest syntax to change uiimagerenderingmode in code when the button was created in storyboard?

FOLLOWING HAS NO EFFECT:

 self.callButton.imageView.tintColor = [UIColor redColor];

FOLLOWING THROWS ERROR property uiimagerenderingmodealwaystemplate not found:

[self.callButton.image.imageWithRenderingMode UIImageRenderingModeAlwaysTemplate];

Thanks for any suggestions.

user6631314
  • 1,751
  • 1
  • 13
  • 44

1 Answers1

1

One way to solve this:

In your storyboard, make sure to set "Render as" to "Template Image" (the image itself should be black & white) and then you can call self.callButton.tintColor = [UIColor redColor].

like this:

Template Image

p.s. I'm using a PDF file for my image, which is why I have the "Single Scale" selected and "Preserve Vector Data" checkbox set to on; if you're using PNG, that checkbox should be set to off and you should have @2x graphics.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215